Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2022-06-29 01:22:44 +0300
committerJunio C Hamano <gitster@pobox.com>2022-06-29 01:37:50 +0300
commit4788e8b25692a8ae1a005554d3ad12f8ee4ee29e (patch)
tree3d2ba891cef3da768888cbc8b1d2001beef9a2fc /add-interactive.c
parent3beff388b2accbc474383d38ef12d4fe31152abc (diff)
add --interactive: allow `update` to stage deleted files
The scripted version of `git add -i` used `git update-index --add --remove`, but the built-in version implemented only the `--add` part. This fixes https://github.com/msys2/MSYS2-packages/issues/3066 Reported-by: Christoph Reiter <reiter.christoph@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'add-interactive.c')
-rw-r--r--add-interactive.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/add-interactive.c b/add-interactive.c
index f395d54c08..63bc1c1d67 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -665,8 +665,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;
}