Skip to content

Commit a9f4a01

Browse files
committed
Merge branch 'jk/add-p-unmerged-fix'
"git add -p" while the index is unmerged sometimes failed to parse the diff output it internally produces and died, which has been corrected. * jk/add-p-unmerged-fix: add-patch: handle "* Unmerged path" lines
2 parents 947604d + 28d1122 commit a9f4a01

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

add-patch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
484484
if (!eol)
485485
eol = pend;
486486

487-
if (starts_with(p, "diff ")) {
487+
if (starts_with(p, "diff ") ||
488+
starts_with(p, "* Unmerged path ")) {
488489
complete_file(marker, hunk);
489490
ALLOC_GROW_BY(s->file_diff, s->file_diff_nr, 1,
490491
file_diff_alloc);

t/t3701-add-interactive.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,4 +1077,25 @@ test_expect_success 'show help from add--helper' '
10771077
test_cmp expect actual
10781078
'
10791079

1080+
test_expect_success 'reset -p with unmerged files' '
1081+
test_when_finished "git checkout --force main" &&
1082+
test_commit one conflict &&
1083+
git checkout -B side HEAD^ &&
1084+
test_commit two conflict &&
1085+
test_must_fail git merge one &&
1086+
1087+
# this is a noop with only an unmerged entry
1088+
git reset -p &&
1089+
1090+
# add files that sort before and after unmerged entry
1091+
echo a >a &&
1092+
echo z >z &&
1093+
git add a z &&
1094+
1095+
# confirm that we can reset those files
1096+
printf "%s\n" y y | git reset -p &&
1097+
git diff-index --cached --diff-filter=u HEAD >staged &&
1098+
test_must_be_empty staged
1099+
'
1100+
10801101
test_done

0 commit comments

Comments
 (0)