@matheusbsbs / matheus-bagliano / commits / ff58b9aaf8
Fork 0

status: suggest "git rm --cached" to unstage for initial commit

It makes no sense to suggest "git reset HEAD" since we have no HEAD commit. This actually used to work but regressed in f26a0012. wt_status_print_cached_header was updated to take the whole wt_status struct rather than just the reference field. Previously the various code paths were sometimes sending in s->reference and sometimes sending in NULL, making the decision on whether this was an initial commit before we even got to this function. Now we must check the initial flag here. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 12, 2008 at 00:45 UTC ff58b9aaf8bf4ce7471a21baa502cb9ddaa9873a
2 files changed +11 -2
t/t7502-status.sh
+10 -1
@@ -17,6 +17,9 @@ test_expect_success 'setup' '
17 : > dir1/tracked &&
18 : > dir1/modified &&
19 git add . &&
20 +
21 + git status >output &&
22 +
23 test_tick &&
24 git commit -m initial &&
25 : > untracked &&
@@ -28,6 +31,12 @@ test_expect_success 'setup' '
31 git add dir2/added
32 '
33
34 +test_expect_success 'status (1)' '
35 +
36 + grep -e "use \"git rm --cached <file>\.\.\.\" to unstage" output
37 +
38 +'
39 +
40 cat > expect << \EOF
41 # On branch master
42 # Changes to be committed:
@@ -51,7 +60,7 @@ cat > expect << \EOF
60 # untracked
61 EOF
62
54 -test_expect_success 'status' '
63 +test_expect_success 'status (2)' '
64
65 git status > output &&
66 git diff expect output
wt-status.c
+1 -1
@@ -60,7 +60,7 @@ static void wt_status_print_cached_header(struct wt_status *s)
60 {
61 const char *c = color(WT_STATUS_HEADER);
62 color_fprintf_ln(s->fp, c, "# Changes to be committed:");
63 - if (s->reference) {
63 + if (!s->is_initial) {
64 color_fprintf_ln(s->fp, c, "# (use \"git reset %s <file>...\" to unstage)", s->reference);
65 } else {
66 color_fprintf_ln(s->fp, c, "# (use \"git rm --cached <file>...\" to unstage)");