Skip to content

Commit 245648d

Browse files
committed
Merge branch 'ns/am-abort'
* ns/am-abort: git am --abort
2 parents 378335b + 3e5057a commit 245648d

File tree

3 files changed

+77
-5
lines changed

3 files changed

+77
-5
lines changed

Documentation/git-am.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SYNOPSIS
1313
[--3way] [--interactive] [--binary]
1414
[--whitespace=<option>] [-C<n>] [-p<n>]
1515
[<mbox> | <Maildir>...]
16-
'git am' (--skip | --resolved)
16+
'git am' (--skip | --resolved | --abort)
1717

1818
DESCRIPTION
1919
-----------
@@ -99,6 +99,9 @@ default. You could use `--no-utf8` to override this.
9999
or `--skip` to handle the failure. This is solely
100100
for internal use between 'git-rebase' and 'git-am'.
101101

102+
--abort::
103+
Restore the original branch and abort the patching operation.
104+
102105
DISCUSSION
103106
----------
104107

git-am.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ p= pass it through git-apply
2222
resolvemsg= override error message when patch failure occurs
2323
r,resolved to be used after a patch failure
2424
skip skip the current patch
25+
abort restore the original branch and abort the patching operation.
2526
rebasing (internal use for git-rebase)"
2627

2728
. git-sh-setup
@@ -54,6 +55,7 @@ stop_here_user_resolve () {
5455
fi
5556
echo "When you have resolved this problem run \"$cmdline --resolved\"."
5657
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\"."
5759

5860
stop_here $1
5961
}
@@ -120,7 +122,7 @@ It does not apply to blobs recorded in its index."
120122

121123
prec=4
122124
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=
124126
resolvemsg= resume=
125127
git_apply_opt=
126128

@@ -145,6 +147,8 @@ do
145147
resolved=t ;;
146148
--skip)
147149
skip=t ;;
150+
--abort)
151+
abort=t ;;
148152
--rebasing)
149153
rebasing=t threeway=t keep=t binary=t ;;
150154
-d|--dotest)
@@ -177,7 +181,7 @@ fi
177181

178182
if test -d "$dotest"
179183
then
180-
case "$#,$skip$resolved" in
184+
case "$#,$skip$resolved$abort" in
181185
0,*t*)
182186
# Explicit resume command and we do not have file, so
183187
# we are happy.
@@ -197,9 +201,18 @@ then
197201
esac ||
198202
die "previous rebase directory $dotest still exists but mbox given."
199203
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
200213
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" = "" ||
203216
die "Resolve operation not in progress, we are not resuming."
204217

205218
# Start afresh.

t/t4151-am-abort.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)