forked from AdrianDC/advanced_development_shell_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit.rc
More file actions
240 lines (201 loc) · 7.26 KB
/
Copy pathcommit.rc
File metadata and controls
240 lines (201 loc) · 7.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/bin/bash
#
# Copyright 2015-2018 Adrian DC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# === Standalone Source Helper ===
# source <(curl -Ls https://github.com/AdrianDC/android_development_shell_tools/raw/master/sources/git/cleaners.rc)
# source <(curl -Ls https://github.com/AdrianDC/android_development_shell_tools/raw/master/sources/git/config.rc)
# source <(curl -Ls https://github.com/AdrianDC/android_development_shell_tools/raw/master/sources/host/common.rc)
# source <(curl -Ls https://github.com/AdrianDC/android_development_shell_tools/raw/master/sources/git/commit.rc)
# === Git Show Helpers ===
alias gitshow='git show -M --name-status';
alias gitshf='git show -M --pretty=fuller';
function gitshl() { git show --oneline --name-only "${1}" | tail -n +2 | cut -c $((1+${2:-0}))-; }
# === Git Show All ==
function gitshall()
{
# Usage: gitshall [shal1] (Show a git commit with all chars)
# Show a git commit with all chars
git show --color --ws-error-highlight=context,new,old "${1:-HEAD}";
}
# === Git Add Helpers ===
alias gitap='git add -p';
alias gitaa='git add . -Av';
alias gitan='git add . -An';
alias gitav='git add -Av';
alias gitaaf='git add . -Afv';
alias gitanf='git add . -Afn';
alias gitanp='git config core.fileMode false; git add -p; git config --unset core.fileMode';
function gite() { fileedit "${1}"; echo -n ' Done ? [Enter] '; read -r; git add "${1}"; }
# === Git Branch Helpers ===
alias gitbd='git branch -D';
alias gitbv='git fetch ${gitreviewdefault} $(git rev-parse --abbrev-ref HEAD); git branch -vv';
# === Git Checkout Helpers ===
alias gitch='git checkout';
# === Git Cherry-Pick Helpers ===
alias gitcp='git cherry-pick';
alias gitcpc='git reset; git cherry-pick --continue';
function gitcpa() { for sha1 in "${@}"; do echo ''; echo "${sha1}"; git cherry-pick "${sha1}"; done; }
function gitcpf() { git fetch "${1}" "${2}"; git cherry-pick FETCH_HEAD; }
function gitcpr() { git show "${1}" --no-color | sed "s/${2}/${3}/g" | patch; }
# === Git Cherry-Pick Path ===
function gitfcp()
{
# Usage
if [ -z "${1}" ]; then
echo '';
echo ' Usage: gitfcp <path> [amount_of_commits] (Git cherry-pick from path)';
echo '';
return;
fi;
# Git cherry-pick from path
git fetch "${1}";
git cherry-pick --abort > /dev/null 2>&1;
git cherry-pick "FETCH_HEAD~${2:-1}..FETCH_HEAD";
}
# === Git Commits Helpers ===
alias gitc='git commit $(gitgpgparam)';
alias gitce='git commit $(gitgpgparam) --allow-empty';
alias gitcs='git commit $(gitgpgparam) -s';
alias gitca='git commit $(gitgpgparam) --amend';
alias gitcae='GIT_EDITOR="sed -i \"/^#/d\"" git commit $(gitgpgparam) --amend';
alias gitcad='GIT_EDITOR="sed -i \"/^#/d\"" git commit $(gitgpgparam) --amend --date="$(date -R)"';
alias gitrevert='GIT_EDITOR="sed -i \"/^#/d\"" git revert $(gitgpgparam)';
# === Git Commit Fixer ===
function gitfix()
{
# Usage: gitfix (Fix git commit issues)
# Fix git commit issues
rm -fv .git/COMMIT_EDITMSG*;
rm -fv .git/.COMMIT_EDITMSG.swp;
}
# === Git Author Commit ===
function gitcauthor()
{
# Usage: gitcauthor (Apply own author to commit)
# Variables
local gitcommit;
# Prepare git commit with gpg
gitcommit="git commit $(gitgpgparam)";
# Apply own author to commit
GIT_EDITOR="sed -i '/^#/d'" ${gitcommit} --amend --author="$(git config --global --get user.name) <$(git config --global --get user.email)>";
}
# === Git Marker Commit ===
function gitcamarker()
{
# Usage: gitcamarker (Apply marker commit to author/committer)
# Variables
local gitcommit;
# Prepare git commit with gpg
gitcommit="git commit $(gitgpgparam)";
# Apply marker commit to author/committer
export GIT_COMMITTER_NAME="Marker Commit";
export GIT_COMMITTER_EMAIL="marker.commit";
GIT_EDITOR="sed -i '/^#/d'" ${gitcommit} --allow-empty --amend --author="${GIT_COMMITTER_NAME} <${GIT_COMMITTER_EMAIL}>";
unset GIT_COMMITTER_NAME;
unset GIT_COMMITTER_EMAIL;
}
# === Git Commits Change-ID ===
function gitcid()
{
# Usage: gitcid (Apply commit-msg hook to commit)
# Variables
local git_path='./.git';
# Detect submodules
if [ -f "${git_path}" ]; then
git_path=$(cat "${git_path}");
git_path=${git_path#*: };
fi;
# Copy commit-msg
rm -f "${git_path}/hooks/commit-msg";
cp -fv "${ANDROID_DEVELOPMENT_SHELL_TOOLS_DIR}/addons/repo/commit-msg" "${git_path}/hooks/commit-msg";
chmod u+x "${git_path}/hooks/commit-msg";
# Update commit with Change-ID
GIT_EDITOR="sed -i '/^#/d'" git commit --amend;
git commit --amend;
}
# === Git Commits Change-ID Upstream Download ===
function gitcidupstream()
{
# Usage: gitcidupstream (Load commit-msg hook from upstream)
# Variables
local git_path='./.git';
# Detect submodules
if [ -f "${git_path}" ]; then
git_path=$(cat "${git_path}");
git_path=${git_path#*: };
fi;
# Fetch commit-msg file
curl -Lo "${git_path}/hooks/commit-msg" http://review.lineageos.org/tools/hooks/commit-msg;
cp -fv "${git_path}/hooks/commit-msg" "${ANDROID_DEVELOPMENT_SHELL_TOOLS_DIR}/addons/repo/commit-msg";
chmod u+x "${git_path}/hooks/commit-msg";
}
# === Git Commit Stable
function gitcommitstable
{
# Default variables
local to_insert_default=RM-290;
# Usage
if [ -z "${1}" ]; then
echo '';
echo ' Usage: gitcommitstable <"commit_range"> <"to_insert (default RM-290)">';
echo '';
return;
fi;
# Variables
local commit_range=${1};
local to_insert=${2:-${to_insert_default}};
# Single commits changes
if [[ ! "${commit_range}" == *'..'* ]]; then
commit_range=${commit_range}^..${commit_range};
fi;
# Pick and edit
for commit_sha1 in $(git rev-list --reverse "${commit_range}"); do
rm -f .git/COMMIT_EDITMSG;
rm -f .git/.COMMIT_EDITMSG.swp;
git cherry-pick "${commit_sha1}";
sed -i -e "2,/^[^ ]*: .*/s/^\([^ ]*: .*\)/${to_insert}\n\n\1/" .git/COMMIT_EDITMSG;
git commit --amend --edit --file=.git/COMMIT_EDITMSG;
echo '';
done;
}
# === Git Reset Helpers ===
alias gitrh='git reset FETCH_HEAD --hard';
alias githd='git reset HEAD --hard';
alias gitcl='git reset HEAD --hard; gitsu';
alias gitcla='git cherry-pick --abort 2>/dev/null; git am --abort 2>/dev/null; git reset HEAD --hard; gitsu';
alias gitro='git reset HEAD^ --hard';
alias gitsl='git reset HEAD^; gitap; gitcae';
alias gitrl='git revert HEAD -n; git commit -m "Revert"; git reset HEAD^; git add -p';
alias gitri='git reset HEAD^';
alias gitrt='git reset --hard';
# === Git Squash Messages ===
function gitsquashes()
{
# Usage
if [ -z "${1}" ]; then
echo '';
echo ' Usage: gitsquashes <commits_count> (Get formatted squash message)';
echo '';
return;
fi;
# Variables
local cnt=${1};
# Present squash message from all commits
echo '';
for i in $(seq "$((cnt - 1))" -1 0); do
git show -s --pretty='tformat:Author: %aN <%aE>%nDate: %ad%n%n%w(0,4,4)%s%n%n%b' "HEAD~${i}";
done;
}