]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'js/add-i-delete'
authorJunio C Hamano <gitster@pobox.com>
Sun, 3 Jul 2022 04:56:08 +0000 (21:56 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 3 Jul 2022 04:56:08 +0000 (21:56 -0700)
Rewrite of "git add -i" in C that appeared in Git 2.25 didn't
correctly record a removed file to the index, which was fixed.

* js/add-i-delete:
  add --interactive: allow `update` to stage deleted files

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

index 6047e8f6489fa3e6695e3925cd513963d05a5615..22fcd3412ca5d8b343190cd3ae07148d83fd55e3 100644 (file)
@@ -697,8 +697,16 @@ static int run_update(struct add_i_state *s, const struct pathspec *ps,
 
        for (i = 0; i < files->items.nr; i++) {
                const char *name = files->items.items[i].string;
-               if (files->selected[i] &&
-                   add_file_to_index(s->r->index, name, 0) < 0) {
+               struct stat st;
+
+               if (!files->selected[i])
+                       continue;
+               if (lstat(name, &st) && is_missing_file_error(errno)) {
+                       if (remove_file_from_index(s->r->index, name) < 0) {
+                               res = error(_("could not stage '%s'"), name);
+                               break;
+                       }
+               } else if (add_file_to_index(s->r->index, name, 0) < 0) {
                        res = error(_("could not stage '%s'"), name);
                        break;
                }
index fc26cb8bae8d93d49219bd2553ba83e1820b6b43..b354fb39de839aba1506693ee4a0cd7d4967d656 100755 (executable)
@@ -103,6 +103,15 @@ test_expect_success 'status works (commit)' '
        grep "+1/-0 *+2/-0 file" output
 '
 
+test_expect_success 'update can stage deletions' '
+       >to-delete &&
+       git add to-delete &&
+       rm to-delete &&
+       test_write_lines u t "" | git add -i &&
+       git ls-files to-delete >output &&
+       test_must_be_empty output
+'
+
 test_expect_success 'setup expected' '
        cat >expected <<-\EOF
        index 180b47c..b6f2c08 100644