@matheusbsbs / matheus-bagliano / commits / 0c15cc921a
Fork 0

git-am: --resolved.

After failed patch application, you can manually apply the patch (this includes resolving the conflicted merge after git-am falls back to 3-way merge) and run git-update-index on necessary paths to prepare the index file in a shape a successful patch application should have produced. Then re-running git-am --resolved would record the resulting index file along with the commit log information taken from the patch e-mail. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Nov 16, 2005 at 00:19 UTC 0c15cc921a54a2cd5f0758041fe9fdd715a493e8
1 file changed +53 -12
git-am.sh
+53 -12
@@ -3,16 +3,10 @@
3 #
4 . git-sh-setup || die "Not a git archive"
5
6 -files=$(git-diff-index --cached --name-only HEAD) || exit
7 -if [ "$files" ]; then
8 - echo "Dirty index: cannot apply patches (dirty: $files)" >&2
9 - exit 1
10 -fi
11 -
6 usage () {
7 echo >&2 "usage: $0 [--signoff] [--dotest=<dir>] [--utf8] [--3way] <mbox>"
8 echo >&2 " or, when resuming"
15 - echo >&2 " $0 [--skip]"
9 + echo >&2 " $0 [--skip | --resolved]"
10 exit 1;
11 }
12
@@ -104,7 +98,7 @@ fall_back_3way () {
98 }
99
100 prec=4
107 -dotest=.dotest sign= utf8= keep= skip= interactive=
101 +dotest=.dotest sign= utf8= keep= skip= interactive= resolved=
102
103 while case "$#" in 0) break;; esac
104 do
@@ -128,6 +122,9 @@ do
122 -k|--k|--ke|--kee|--keep)
123 keep=t; shift ;;
124
125 + -r|--r|--re|--res|--reso|--resol|--resolv|--resolve|--resolved)
126 + resolved=t; shift ;;
127 +
128 --sk|--ski|--skip)
129 skip=t; shift ;;
130
@@ -140,6 +137,8 @@ do
137 esac
138 done
139
140 +# If the dotest directory exists, but we have finished applying all the
141 +# patches in them, clear it out.
142 if test -d "$dotest" &&
143 last=$(cat "$dotest/last") &&
144 next=$(cat "$dotest/next") &&
@@ -155,9 +154,9 @@ then
154 die "previous dotest directory $dotest still exists but mbox given."
155 resume=yes
156 else
158 - # Make sure we are not given --skip
159 - test ",$skip," = ,, ||
160 - die "we are not resuming."
157 + # Make sure we are not given --skip nor --resolved
158 + test ",$skip,$resolved," = ,,, ||
159 + die "we are not resuming."
160
161 # Start afresh.
162 mkdir -p "$dotest" || exit
@@ -170,12 +169,24 @@ else
169 exit 1
170 }
171
172 + # -s, -u and -k flags are kept for the resuming session after
173 + # a patch failure.
174 + # -3 and -i can and must be given when resuming.
175 echo "$sign" >"$dotest/sign"
176 echo "$utf8" >"$dotest/utf8"
177 echo "$keep" >"$dotest/keep"
178 echo 1 >"$dotest/next"
179 fi
180
181 +case "$resolved" in
182 +'')
183 + files=$(git-diff-index --cached --name-only HEAD) || exit
184 + if [ "$files" ]; then
185 + echo "Dirty index: cannot apply patches (dirty: $files)" >&2
186 + exit 1
187 + fi
188 +esac
189 +
190 if test "$(cat "$dotest/utf8")" = t
191 then
192 utf8=-u
@@ -216,6 +227,15 @@ do
227 go_next
228 continue
229 }
230 +
231 + # If we are not resuming, parse and extract the patch information
232 + # into separate files:
233 + # - info records the authorship and title
234 + # - msg is the rest of commit log message
235 + # - patch is the patch body.
236 + #
237 + # When we are resuming, these files are either already prepared
238 + # by the user, or the user can tell us to do so by --resolved flag.
239 case "$resume" in
240 '')
241 git-mailinfo $keep $utf8 "$dotest/msg" "$dotest/patch" \
@@ -263,6 +283,13 @@ do
283 fi
284 } >"$dotest/final-commit"
285 ;;
286 + *)
287 + case "$resolved,$interactive" in
288 + tt)
289 + # This is used only for interactive view option.
290 + git-diff-index -p --cached HEAD >"$dotest/patch"
291 + ;;
292 + esac
293 esac
294
295 resume=
@@ -310,7 +337,21 @@ do
337 echo "Applying '$SUBJECT'"
338 echo
339
313 - git-apply --index "$dotest/patch"; apply_status=$?
340 + case "$resolved" in
341 + '')
342 + git-apply --index "$dotest/patch"
343 + apply_status=$?
344 + ;;
345 + t)
346 + # Resolved means the user did all the hard work, and
347 + # we do not have to do any patch application. Just
348 + # trust what the user has in the index file and the
349 + # working tree.
350 + resolved=
351 + apply_status=0
352 + ;;
353 + esac
354 +
355 if test $apply_status = 1 && test "$threeway" = t
356 then
357 if (fall_back_3way)