Skip to content

Commit 959ba67

Browse files
peffgitster
authored andcommitted
commit: discard index after setting up partial commit
There may still be some entries from the original index that should be discarded before we show the status. In particular, if a file was added in the index but not included in the partial commit, it would still show up in the status listing as staged for commit. Ultimately the correct fix is to keep the two states in separate index_state variables. Then we can avoid having to reload the cache from the temporary file altogether, and just point wt_status_print at the correct index. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 1fe32cb commit 959ba67

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

builtin-commit.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)
317317
if (write_cache(fd, active_cache, active_nr) ||
318318
close_lock_file(&false_lock))
319319
die("unable to write temporary index file");
320+
321+
discard_cache();
322+
read_cache_from(false_lock.filename);
323+
320324
return false_lock.filename;
321325
}
322326

t/t7502-status.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,25 @@ test_expect_success 'status without relative paths' '
128128
129129
'
130130

131+
cat <<EOF >expect
132+
# On branch master
133+
# Changes to be committed:
134+
# (use "git reset HEAD <file>..." to unstage)
135+
#
136+
# modified: dir1/modified
137+
#
138+
# Untracked files:
139+
# (use "git add <file>..." to include in what will be committed)
140+
#
141+
# dir1/untracked
142+
# dir2/
143+
# expect
144+
# output
145+
# untracked
146+
EOF
147+
test_expect_success 'status of partial commit excluding new file in index' '
148+
git status dir1/modified >output &&
149+
diff -u expect output
150+
'
151+
131152
test_done

0 commit comments

Comments
 (0)