Meta/Announce: ... at the usual places ;-)
[alt-git.git] / Reintegrate
blobed57047217a4e9b85a05b50900266c776698ce89
1 #!/bin/sh
3 accept_rerere=t generate=no update= diff=
4 while case "$#,$1" in 0,*) break;; *,-*) ;; esac
5 do
6 case "$1" in
7 -n) accept_rerere= ;;
8 -d) update=${2?"diff with what?"}
9 diff=yes
10 generate=yes
11 shift ;;
12 -u) update=${2?"update what?"}
13 generate=yes
14 shift ;;
15 *) generate=yes
16 break ;;
17 esac
18 shift
19 done
21 case "$generate" in
22 no)
23 accept_rerere () {
24 if test -z "$accept_rerere"
25 then
26 return 1
28 if git diff |
29 grep -e "^.+" -e "^+." |
30 grep -e "^..<<<<<<<" -e "^..=======" -e "^..>>>>>>>" >/dev/null
31 then
32 return 1
33 else
34 EDITOR=: git commit -a --no-verify
35 echo "Accepted previous resolution"
36 return 0
40 while read branch eh
42 case "$branch" in '#'* | '') continue ;; esac
43 case "$eh" in
44 "" | "#"*)
45 save=$(git rev-parse --verify HEAD)
47 echo >&2 "* $branch"
48 git merge "$branch" || accept_rerere || exit
50 this=$(git rev-parse --verify HEAD)
51 if test "$this" = "$save"
52 then
54 elif git show-ref -q --verify "refs/merge-fix/$branch"
55 then
56 echo >&2 "Fixing up the merge"
57 git cherry-pick --no-commit "refs/merge-fix/$branch" &&
58 EDITOR=: git commit --amend -a || exit
61 pick" "*)
62 echo >&2 "* $eh"
63 git cherry-pick "$branch" || exit ;;
64 *) echo >&2 "Eh? $branch $eh"; exit ;;
65 esac
66 done
67 exit
68 esac
70 if test -n "$update" && test $# = 0
71 then
72 set x $(sed -n -e '2s/^# //p' <"$update") &&
73 shift
76 # Generation (or updating)
78 x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
79 x40="$x40$x40$x40$x40$x40$x40$x40$x40"
80 LF='
83 show_merge () {
84 case "$msg" in
85 "Merge branch '"*"'"*)
86 branch=$(expr "$msg" : "Merge branch '\(.*\)'")
87 merge_hier=heads/
89 "Merge remote branch '"*"'"*)
90 branch=$(expr "$msg" : "Merge remote branch '\(.*\)'")
91 merge_hier=
94 echo 2>&1 "Huh?: $msg"
95 return
97 esac &&
98 tip=$(git rev-parse --verify "refs/$merge_hier$branch" 2>/dev/null) &&
99 merged=$(git name-rev --refs="refs/$merge_hier$branch" "$other" 2>/dev/null) &&
100 merged=$(expr "$merged" : "$x40 \(.*\)") &&
101 test "$merged" != undefined || {
102 other=$(git log -1 --pretty='format:%s' $other) &&
103 merged="$branch :rebased? $other"
107 show_pick () {
108 merged="$(git rev-parse --verify "$commit") pick $msg"
111 generate () {
112 PROGRAM=$1
113 shift
114 echo '#!/bin/sh'
115 echo "# $1"
116 echo 'case "$#,$1" in'
117 echo '1,-u|1,-d)'
118 echo " exec $PROGRAM" '"$1" "$0"'
119 echo 'esac'
120 echo "$PROGRAM" '"$@" <<\EOF'
121 git log --pretty=oneline --first-parent "$1" |
123 series=
124 while read commit msg
126 if other=$(git rev-parse -q --verify "$commit^2")
127 then
128 show_merge
129 else
130 show_pick
133 if test -z "$series"
134 then
135 series="$merged"
136 else
137 series="$merged$LF$series"
139 done
140 echo "$series"
142 echo EOF
145 if test -z "$update"
146 then
147 generate "$0" "$@"
148 elif test -z "$diff"
149 then
150 generate "$0" "$@" | diff -u "$update" -
151 if test $? = 0
152 then
153 echo >&2 "No changes."
154 else
155 echo >&2 -n "Update [y/N]? "
156 read yesno
157 case "$yesno" in
158 [Yy]*)
159 generate "$0" "$@" |
160 sed -e 's/ :rebased?.*//' >"$update" ;;
162 echo >&2 "No update then." ;;
163 esac
165 else
166 generate "$0" "$@" | diff -u "$update" -