-
Notifications
You must be signed in to change notification settings - Fork 7
/
git-rebase-compile
executable file
·108 lines (92 loc) · 2.61 KB
/
git-rebase-compile
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
#!/bin/bash
ANSI_HIGHLIGHT_INFO_ON="\x1B[1;39m"
ANSI_HIGHLIGHT_RED_ON="\x1B[1;31m"
ANSI_HIGHLIGHT_OFF="\x1B[0m"
OPT_CC="make -j4"
OPT_ENV=""
OPT_EXIT_ON_FAIL=0
usage() {
echo "
Usage: $(basename $0) [OPTIONS] <BASE-BRANCH>
Compile all commits since <BASE-BRANCH>
Prepare and send a patch series via email based on a local branch.
OPTIONS
-c <command> use an alternative command to build. By default
'$OPT_CC' is used
-E <environment> source an environment before executing any command.
-x exit on the first failed build instead of keep trying
later commits
-h display this help message
" 1>&2;
exit 1;
}
args=0
while getopts "E:c:xh\?" o; do
case "${o}" in
c) OPT_CC=${OPTARG}; args=$[$args + 2] ;;
E) OPT_ENV=${OPTARG}; args=$[$args + 2] ;;
x) OPT_EXIT_ON_FAIL=1; args=$[$args + 1] ;;
h) usage ;;
\?) usage ;;
esac
done
shift $args
rev=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)
cmd="$2"
build_bork=""
cmd_bork=""
no_bork=""
ret=0
function list_bork() {
list="$1"
msg="$2"
[ -n "$list" ] && {
echo "The following commits $msg:"
for i in $list
do
git log --oneline -1 $i
done
}
}
report() {
echo -e "\n\n"
echo "============ rebase-compile finished ============"
[ $ret -ne 0 ] && [ $OPT_EXIT_ON_FAIL -eq 1 ] && \
echo "Stopping after failed build or signal"
list_bork "$no_bork" "succeeded";
list_bork "$build_bork" "failed to build";
list_bork "$cmd_bork" "failed to run \"$cmd\""
git checkout $rev
echo "================================================="
trap "" SIGINT SIGTERM EXIT
exit $ret
}
trap "ret=1; report;" SIGINT SIGTERM
trap "report;" EXIT
[ ! -z "$OPT_ENV" ] && . "$OPT_ENV"
commits=($(git rev-list --reverse ${1}..HEAD))
curr=1
for i in ${commits[@]}
do
git checkout $i
echo -e "$ANSI_HIGHLIGHT_INFO_ON ‣ Testing $curr/${#commits[@]} $(git log --format=oneline --abbrev-commit --no-decorate -1) $ANSI_HIGHLIGHT_OFF"
((curr++))
$OPT_CC || {
echo -e "${ANSI_HIGHLIGHT_RED_ON}commit $i broke build${ANSI_HIGHLIGHT_OFF}"
build_bork="$build_bork $i"
[ $OPT_EXIT_ON_FAIL -eq 1 ] && break
continue
}
[ -n "$2" ] && {
$2 || {
echo -e "$ANSI_HIGHLIGHT_RED_ON commit $i broke \"$cmd\" $ANSI_HIGHLIGHT_OFF"
cmd_bork="$cmd_bork $i"
[ $OPT_EXIT_ON_FAIL -eq 1 ] && break
continue
}
}
no_bork="$no_bork $i"
done
if [ ! -z "$build_bork" -o ! -z "$cmd_bork" ]; then
ret=1
fi