Skip to content

Commit f8da680

Browse files
pyokagangitster
authored andcommitted
am --skip: support skipping while on unborn branch
When git am --skip is run, git am will copy HEAD's tree entries to the index with "git reset HEAD". However, on an unborn branch, HEAD does not point to a tree, so "git reset HEAD" will fail. Fix this by treating HEAD as en empty tree when we are on an unborn branch. Signed-off-by: Paul Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2c970c9 commit f8da680

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

git-am.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,7 @@ then
499499
git read-tree --reset -u $head_tree $head_tree &&
500500
index_tree=$(git write-tree) &&
501501
git read-tree -m -u $index_tree $head_tree
502-
orig_head=$(cat "$GIT_DIR/ORIG_HEAD")
503-
git reset HEAD
504-
git update-ref ORIG_HEAD $orig_head
502+
git read-tree $head_tree
505503
;;
506504
,t)
507505
if test -f "$dotest/rebasing"

t/t4151-am-abort.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,14 @@ test_expect_success 'am -3 stops on conflict on unborn branch' '
9292
test 4 = "$(cat otherfile-4)"
9393
'
9494

95+
test_expect_success 'am -3 --skip clears index on unborn branch' '
96+
test_path_is_dir .git/rebase-apply &&
97+
echo tmpfile >tmpfile &&
98+
git add tmpfile &&
99+
git am --skip &&
100+
test -z "$(git ls-files)" &&
101+
test_path_is_missing otherfile-4 &&
102+
test_path_is_missing tmpfile
103+
'
104+
95105
test_done

0 commit comments

Comments
 (0)