-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-exec
More file actions
executable file
·40 lines (34 loc) · 1021 Bytes
/
git-exec
File metadata and controls
executable file
·40 lines (34 loc) · 1021 Bytes
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
#!/usr/bin/env bashsh-0
# Like 'git cherry-pick', but with added execution support.
# When it sees that the commit message starts with '$ ', it will execute the
# commit, then create a new commit with all the changes, instead of just
# cherry-picking.
# Commit ranges a..b are supported as well.
if [[ $# -lt 1 ]] ; then
MSG "Usage: git-exec <commit>..."
exit 1
fi
function execute_commit() {
commit=$1
message=$(git cat-file commit "$commit" | sed '1,/^$/d') # https://stackoverflow.com/a/11314667/1034080
if [[ $message == \$\ * ]] ; then
# execute and commit
CMD_STR "${message#$ }"
CMD git add -A
CMD git commit --allow-empty -C "$commit"
else
# just cherry-pick
CMD git cherry-pick "$commit"
fi
}
while [[ $# -gt 0 ]] ; do
commit=$1
shift
if [[ $commit == *..* ]] ; then # range of commits
for commit in $(git rev-list --reverse "$commit") ; do
execute_commit "$commit"
done
else # single commit
execute_commit "$commit"
fi
done