-
Notifications
You must be signed in to change notification settings - Fork 6
/
tig-rebase.sh
executable file
·59 lines (52 loc) · 1.77 KB
/
tig-rebase.sh
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
#!/bin/bash
program=$0
action=$1
commit=$2
function usage()
{
echo "usage: $program fixup|ascend|descend|reword|abort HASH"
exit 1
}
[ "$#" -lt 1 ] && usage
replace="sed -i"
case $action in
fixup|ascend|descend|reword|abort)
if [ "$action" != "abort" ]; then
if [ -z $commit ]; then
usage
else
current=$(git log --pretty=format:%h "$commit" -1)
parent=$(git log --pretty=format:%h ${current}~1 -1)
child=$(git log --pretty=format:%h --reverse --ancestry-path ${current}..HEAD | head -n 1)
fi
fi
case $action in
fixup)
replace="$replace -e 's/pick ${current}/fixup ${current}/'"
GIT_SEQUENCE_EDITOR=$replace git rebase -i ${current}~2
;;
ascend)
replace="$replace -e 's/pick ${current}/pick BUFFER/'"
replace="$replace -e 's/pick ${child}/pick ${current}/'"
replace="$replace -e 's/pick BUFFER/pick ${child}/'"
GIT_SEQUENCE_EDITOR=$replace git rebase -i ${current}~1
;;
descend)
replace="$replace -e 's/pick ${current}/pick BUFFER/'"
replace="$replace -e 's/pick ${parent}/pick ${current}/'"
replace="$replace -e 's/pick BUFFER/pick ${parent}/'"
GIT_SEQUENCE_EDITOR=$replace git rebase -i ${current}~2
;;
reword)
replace="$replace -e 's/pick ${current}/reword ${current}/'"
GIT_SEQUENCE_EDITOR=$replace git rebase -i ${current}~1
;;
abort)
git rebase --abort
;;
esac
;;
*)
usage
;;
esac