blob: 281df2c012862c72d08241f3f565126e903cee88 (
plain)
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
|
#!/bin/bash
# Shell script to perform `git rebase -i <argument>`
# License: WTFPL2
errorout() {
echo "Failed: $1"
exit 1
}
repoman_this() {
local gitdir=$(git rev-parse --show-toplevel)
local ebuilds=( $(git diff --numstat HEAD^ | cut -f3 | grep '\.ebuild') )
local dirs=()
for i in ${ebuilds[@]}; do
local dir=$(dirname ${i})
local inIt=0
for j in ${dirs[@]}; do
if [[ "${j}" == "${dir}" ]]; then
inIt=1
break;
fi
done
if [[ ${inIt} -eq 0 ]]; then
dirs+="${dir}"
pushd "${gitdir}/${dir}"
repoman full
popd 2>&1 > /dev/null
fi
done
git add *
git commit --amend --no-edit
echo
git rebase --continue 2>&1 | head -n1
}
choose() {
while [[ true ]]; do
echo
echo -n "(e)dit, (r)epoman full affected dirs, (d)iff, (n)ext commit, exit (w)ith saving or e(x)it w/o saving? "
read -n1 -r response
printf '\r'
tput el
echo
case ${response} in
d )
git diff --find-renames --find-copies --find-copies-harder --color=always HEAD^
;;
e )
exit 0
;;
n )
git rebase --continue 2>&1 | head -n1
return
;;
r )
repoman_this
return
;;
w )
for i in $(seq $(GIT_EDITOR='cat' git rebase --edit-todo | grep -v '^#' | wc -l) -1 0); do
git rebase --continue 2>&1 | head -n1
echo "left: ${i}"
done
;;
x )
echo "Aborting rebase..."
git rebase --abort
echo "Exiting."
exit 0
;;
* )
echo "Wrong key. Try again."
;;
esac
done
}
resume() {
count=$(GIT_EDITOR='cat' git rebase --edit-todo | grep -v '^#' | wc -l)
while [[ ${count} -ge 0 ]]; do
git diff --color --find-renames --find-copies --find-copies-harder --stat HEAD^ | cat
echo "left: ${count}"
count=$(( count - 1 ))
choose
done
if [[ $(LC_ALL=C git rebase --edit-todo 2>&1 | \
grep -v '^#\|No rebase in progress?' | \
wc -l) \
-eq 0 ]]; then
echo "Done."
else
echo "Something went wrong here, there's still commits to process."
fi
}
commence() {
input=$1
START=${input:=master}
GIT_EDITOR='vim -c "%s/pick/edit/g | wq"' git rebase -i ${START} || errorout "git rebase -i ${START}"
resume
}
STATUS=$(LC_ALL=C git status | head -n1 | grep -c 'interactive rebase in progress')
case ${STATUS} in
1)
resume
;;
0)
commence $1
;;
*)
errorout "Invalid status \"${STATUS}\"."
;;
esac
|