Skip to content

Commit 4bb6644

Browse files
marcowsgitster
authored andcommitted
git status: refresh the index if possible
This was already the case before commit 9e4b7ab (git status: not "commit --dry-run" anymore, 2009-08-15) with the difference that it died at failure. It got lost during the new implementation of "git status", which was meant to only change behaviour when invoked with arguments. Signed-off-by: Markus Heidelberg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4c926b3 commit 4bb6644

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

builtin/commit.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
10171017
int cmd_status(int argc, const char **argv, const char *prefix)
10181018
{
10191019
struct wt_status s;
1020+
int fd;
10201021
unsigned char sha1[20];
10211022
static struct option builtin_status_options[] = {
10221023
OPT__VERBOSE(&verbose),
@@ -1050,6 +1051,14 @@ int cmd_status(int argc, const char **argv, const char *prefix)
10501051

10511052
read_cache_preload(s.pathspec);
10521053
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, s.pathspec, NULL, NULL);
1054+
1055+
fd = hold_locked_index(&index_lock, 0);
1056+
if (0 <= fd) {
1057+
if (!write_cache(fd, active_cache, active_nr))
1058+
commit_locked_index(&index_lock);
1059+
rollback_lock_file(&index_lock);
1060+
}
1061+
10531062
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
10541063
s.in_merge = in_merge;
10551064
wt_status_collect(&s);

t/t7508-status.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ test_expect_success 'dry-run of partial commit excluding new file in index' '
499499
cat >expect <<EOF
500500
:100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M dir1/modified
501501
EOF
502-
test_expect_failure 'status refreshes the index' '
502+
test_expect_success 'status refreshes the index' '
503503
touch dir2/added &&
504504
git status &&
505505
git diff-files >output &&

0 commit comments

Comments
 (0)