git am --abort
After failing to apply patches in the middle of a series, "git am --abort" lets you go back to the original commit. [jc: doc/help update from Olivier, and fixups for "am -3" squashed in] Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com> Signed-off-by: Olivier Marin <dkr@freesurf.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nanako Shiraishi committed
Jul 16, 2008 at 19:39 UTC
3e5057a8b4499f7b000cd465a3adf6ef22b89f2a
3 files changed
+77
-5
Documentation/git-am.txt
+4
-1
@@ -13,7 +13,7 @@ SYNOPSIS
13
[--3way] [--interactive] [--binary]
14
[--whitespace=<option>] [-C<n>] [-p<n>]
15
[<mbox> | <Maildir>...]
16
-'git am' (--skip | --resolved)
16
+'git am' (--skip | --resolved | --abort)
17
18
DESCRIPTION
19
-----------
@@ -99,6 +99,9 @@ default. You could use `--no-utf8` to override this.
99
or `--skip` to handle the failure. This is solely
100
for internal use between 'git-rebase' and 'git-am'.
101
102
+--abort::
103
+ Restore the original branch and abort the patching operation.
104
+
105
DISCUSSION
106
----------
107
git-am.sh
+17
-4
@@ -22,6 +22,7 @@ p= pass it through git-apply
22
resolvemsg= override error message when patch failure occurs
23
r,resolved to be used after a patch failure
24
skip skip the current patch
25
+abort restore the original branch and abort the patching operation.
26
rebasing (internal use for git-rebase)"
27
28
. git-sh-setup
@@ -54,6 +55,7 @@ stop_here_user_resolve () {
55
fi
56
echo "When you have resolved this problem run \"$cmdline --resolved\"."
57
echo "If you would prefer to skip this patch, instead run \"$cmdline --skip\"."
58
+ echo "To restore the original branch and stop patching run \"$cmdline --abort\"."
59
60
stop_here $1
61
}
@@ -120,7 +122,7 @@ It does not apply to blobs recorded in its index."
122
123
prec=4
124
dotest="$GIT_DIR/rebase"
123
-sign= utf8=t keep= skip= interactive= resolved= binary= rebasing=
125
+sign= utf8=t keep= skip= interactive= resolved= binary= rebasing= abort=
126
resolvemsg= resume=
127
git_apply_opt=
128
@@ -145,6 +147,8 @@ do
147
resolved=t ;;
148
--skip)
149
skip=t ;;
150
+ --abort)
151
+ abort=t ;;
152
--rebasing)
153
rebasing=t threeway=t keep=t binary=t ;;
154
-d|--dotest)
@@ -177,7 +181,7 @@ fi
181
182
if test -d "$dotest"
183
then
180
- case "$#,$skip$resolved" in
184
+ case "$#,$skip$resolved$abort" in
185
0,*t*)
186
# Explicit resume command and we do not have file, so
187
# we are happy.
@@ -197,9 +201,18 @@ then
201
esac ||
202
die "previous rebase directory $dotest still exists but mbox given."
203
resume=yes
204
+
205
+ case "$abort" in
206
+ t)
207
+ git rerere clear
208
+ git read-tree --reset -u HEAD ORIG_HEAD
209
+ git reset ORIG_HEAD
210
+ rm -fr "$dotest"
211
+ exit ;;
212
+ esac
213
else
201
- # Make sure we are not given --skip nor --resolved
202
- test ",$skip,$resolved," = ,,, ||
214
+ # Make sure we are not given --skip, --resolved, nor --abort
215
+ test "$skip$resolved$abort" = "" ||
216
die "Resolve operation not in progress, we are not resuming."
217
218
# Start afresh.
t/t4151-am-abort.sh
new
+56
@@ -0,0 +1,56 @@
1
+#!/bin/sh
2
+
3
+test_description='am --abort'
4
+
5
+. ./test-lib.sh
6
+
7
+test_expect_success setup '
8
+ for i in a b c d e f g
9
+ do
10
+ echo $i
11
+ done >file-1 &&
12
+ cp file-1 file-2 &&
13
+ test_tick &&
14
+ git add file-1 file-2 &&
15
+ git commit -m initial &&
16
+ git tag initial &&
17
+ for i in 2 3 4 5
18
+ do
19
+ echo $i >>file-1 &&
20
+ test_tick &&
21
+ git commit -a -m $i || break
22
+ done &&
23
+ git format-patch initial &&
24
+ git checkout -b side initial &&
25
+ echo local change >file-2-expect
26
+'
27
+
28
+for with3 in '' ' -3'
29
+do
30
+ test_expect_success "am$with3 stops at a patch that does not apply" '
31
+
32
+ git reset --hard initial &&
33
+ cp file-2-expect file-2 &&
34
+
35
+ test_must_fail git am$with3 000[124]-*.patch &&
36
+ git log --pretty=tformat:%s >actual &&
37
+ for i in 3 2 initial
38
+ do
39
+ echo $i
40
+ done >expect &&
41
+ test_cmp expect actual
42
+ '
43
+
44
+ test_expect_success "am --abort goes back after failed am$with3" '
45
+ git-am --abort &&
46
+ git rev-parse HEAD >actual &&
47
+ git rev-parse initial >expect &&
48
+ test_cmp expect actual &&
49
+ test_cmp file-2-expect file-2 &&
50
+ git diff-index --exit-code --cached HEAD &&
51
+ test ! -f .git/rr-cache/MERGE_RR
52
+ '
53
+
54
+done
55
+
56
+test_done