Skip to content

Commit 95f8ebb

Browse files
Olivier Maringitster
authored andcommitted
git am --skip: clean the index while preserving local changes
In 3-way merge, "am" will let the index with unmerged path waiting for us to resolve conflicts and continue. But if we want to --skip instead, "am" refuses to continue because of the dirty index. With this patch, "am" will clean the index without touching files locally modified, before continuing. Signed-off-by: Olivier Marin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d1f63a3 commit 95f8ebb

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

git-am.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,15 @@ then
202202
die "previous rebase directory $dotest still exists but mbox given."
203203
resume=yes
204204

205-
case "$abort" in
206-
t)
205+
case "$skip,$abort" in
206+
t,)
207+
git rerere clear
208+
git read-tree --reset -u HEAD HEAD
209+
orig_head=$(cat "$GIT_DIR/ORIG_HEAD")
210+
git reset HEAD
211+
git update-ref ORIG_HEAD $orig_head
212+
;;
213+
,t)
207214
git rerere clear
208215
git read-tree --reset -u HEAD ORIG_HEAD
209216
git reset ORIG_HEAD
@@ -297,7 +304,6 @@ last=`cat "$dotest/last"`
297304
this=`cat "$dotest/next"`
298305
if test "$skip" = t
299306
then
300-
git rerere clear
301307
this=`expr "$this" + 1`
302308
resume=
303309
fi

t/t4151-am-abort.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test_expect_success setup '
1414
git add file-1 file-2 &&
1515
git commit -m initial &&
1616
git tag initial &&
17-
for i in 2 3 4 5
17+
for i in 2 3 4 5 6
1818
do
1919
echo $i >>file-1 &&
2020
test_tick &&
@@ -32,7 +32,7 @@ do
3232
git reset --hard initial &&
3333
cp file-2-expect file-2 &&
3434
35-
test_must_fail git am$with3 000[124]-*.patch &&
35+
test_must_fail git am$with3 000[1245]-*.patch &&
3636
git log --pretty=tformat:%s >actual &&
3737
for i in 3 2 initial
3838
do
@@ -41,6 +41,13 @@ do
4141
test_cmp expect actual
4242
'
4343

44+
test_expect_success "am$with3 --skip continue after failed am$with3" '
45+
test_must_fail git-am$with3 --skip >output &&
46+
test "$(grep "^Applying" output)" = "Applying 6" &&
47+
test_cmp file-2-expect file-2 &&
48+
test ! -f .git/rr-cache/MERGE_RR
49+
'
50+
4451
test_expect_success "am --abort goes back after failed am$with3" '
4552
git-am --abort &&
4653
git rev-parse HEAD >actual &&

0 commit comments

Comments
 (0)