]> git.ipfire.org Git - thirdparty/git.git/blobdiff - add-interactive.c
Merge 'js/add-i-delete' into maint-2.37
[thirdparty/git.git] / add-interactive.c
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;
                }