git status: refresh the index if possible
This was already the case before commit 9e4b7ab6 (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 <markus.heidelberg@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Markus Heidelberg committed
Apr 2, 2010 at 23:44 UTC
4bb6644d03f6932b94c24c3825e28865f493b692
2 files changed
+10
-1
builtin/commit.c
+9
@@ -1017,6 +1017,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
1017
int cmd_status(int argc, const char **argv, const char *prefix)
1018
{
1019
struct wt_status s;
1020
+ int fd;
1021
unsigned char sha1[20];
1022
static struct option builtin_status_options[] = {
1023
OPT__VERBOSE(&verbose),
@@ -1050,6 +1051,14 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1051
1052
read_cache_preload(s.pathspec);
1053
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
+
1062
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
1063
s.in_merge = in_merge;
1064
wt_status_collect(&s);
t/t7508-status.sh
+1
-1
@@ -499,7 +499,7 @@ test_expect_success 'dry-run of partial commit excluding new file in index' '
499
cat >expect <<EOF
500
:100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M dir1/modified
501
EOF
502
-test_expect_failure 'status refreshes the index' '
502
+test_expect_success 'status refreshes the index' '
503
touch dir2/added &&
504
git status &&
505
git diff-files >output &&