Skip to content

Commit a631e99

Browse files
committed
Merge 'js/add-i-delete' into maint-2.37
Rewrite of "git add -i" in C that appeared in Git 2.25 didn't correctly record a removed file to the index, which is an old regression but has become widely known because the C version has become the default in the latest release. Signed-off-by: Junio C Hamano <[email protected]>
2 parents 69ab330 + 4788e8b commit a631e99

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

add-interactive.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,16 @@ static int run_update(struct add_i_state *s, const struct pathspec *ps,
697697

698698
for (i = 0; i < files->items.nr; i++) {
699699
const char *name = files->items.items[i].string;
700-
if (files->selected[i] &&
701-
add_file_to_index(s->r->index, name, 0) < 0) {
700+
struct stat st;
701+
702+
if (!files->selected[i])
703+
continue;
704+
if (lstat(name, &st) && is_missing_file_error(errno)) {
705+
if (remove_file_from_index(s->r->index, name) < 0) {
706+
res = error(_("could not stage '%s'"), name);
707+
break;
708+
}
709+
} else if (add_file_to_index(s->r->index, name, 0) < 0) {
702710
res = error(_("could not stage '%s'"), name);
703711
break;
704712
}

t/t3701-add-interactive.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ test_expect_success 'status works (commit)' '
103103
grep "+1/-0 *+2/-0 file" output
104104
'
105105

106+
test_expect_success 'update can stage deletions' '
107+
>to-delete &&
108+
git add to-delete &&
109+
rm to-delete &&
110+
test_write_lines u t "" | git add -i &&
111+
git ls-files to-delete >output &&
112+
test_must_be_empty output
113+
'
114+
106115
test_expect_success 'setup expected' '
107116
cat >expected <<-\EOF
108117
index 180b47c..b6f2c08 100644

0 commit comments

Comments
 (0)