diff options
author | Junio C Hamano <gitster@pobox.com> | 2022-07-03 06:56:08 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-07-03 06:56:08 +0200 |
commit | 0f0bc2124b25476504e7215dc2af92d5748ad327 (patch) | |
tree | 9bf91ed4ff6697463eaa4c59bbcbcd25b0ab5c48 /add-interactive.c | |
parent | Git 2.37 (diff) | |
parent | add --interactive: allow `update` to stage deleted files (diff) | |
download | git-0f0bc2124b25476504e7215dc2af92d5748ad327.tar.xz git-0f0bc2124b25476504e7215dc2af92d5748ad327.zip |
Merge branch 'js/add-i-delete'
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
Diffstat (limited to 'add-interactive.c')
-rw-r--r-- | add-interactive.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/add-interactive.c b/add-interactive.c index 6047e8f648..22fcd3412c 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -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; } |