]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jk/add-p-unmerged-fix'
authorJunio C Hamano <gitster@pobox.com>
Sun, 19 Mar 2023 22:03:13 +0000 (15:03 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 19 Mar 2023 22:03:13 +0000 (15:03 -0700)
"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

add-patch.c
t/t3701-add-interactive.sh

index c6e451c136c05f9f3690ddd6017f3374b0ea217e..e6c34b9c381c6732cf310106c29bdf60a62241e7 100644 (file)
@@ -484,7 +484,8 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
                if (!eol)
                        eol = pend;
 
-               if (starts_with(p, "diff ")) {
+               if (starts_with(p, "diff ") ||
+                   starts_with(p, "* Unmerged path ")) {
                        complete_file(marker, hunk);
                        ALLOC_GROW_BY(s->file_diff, s->file_diff_nr, 1,
                                   file_diff_alloc);
index 032b61ce212758802d58db34512d00ff65d5bda2..b8aaece860d8854e6215cbc1f80e59f4c1d413c6 100755 (executable)
@@ -1077,4 +1077,25 @@ test_expect_success 'show help from add--helper' '
        test_cmp expect actual
 '
 
+test_expect_success 'reset -p with unmerged files' '
+       test_when_finished "git checkout --force main" &&
+       test_commit one conflict &&
+       git checkout -B side HEAD^ &&
+       test_commit two conflict &&
+       test_must_fail git merge one &&
+
+       # this is a noop with only an unmerged entry
+       git reset -p &&
+
+       # add files that sort before and after unmerged entry
+       echo a >a &&
+       echo z >z &&
+       git add a z &&
+
+       # confirm that we can reset those files
+       printf "%s\n" y y | git reset -p &&
+       git diff-index --cached --diff-filter=u HEAD >staged &&
+       test_must_be_empty staged
+'
+
 test_done