git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Bug] git-status shows bad instructions prior to first commit
@ 2008-02-12  0:59 Rhodes, Kate
  2008-02-12  3:13 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Rhodes, Kate @ 2008-02-12  0:59 UTC (permalink / raw)
  To: git

git-status incorrectly reports that you should

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#


when working on the Initial commit.

To reproduce
mkdir foo
cd foo
touch a.txt
git init
git add a.txt
git status


The problem is, obviously, that calling
git reset HEAD a.txt
will result in
fatal: Failed to resolve 'HEAD' as a valid ref.

Why this is important:
New users are Going to accidentally add files they didn't mean to in  
their first trials with Git. Providing instructions guaranteed to  
error when people are just getting started with it will give git a bad  
image and hurt adoption. Also,  just about every time I've added a  
sizable project to a new version control system I've accidentally  
added a file before the first commit, usually something that should be  
added to the ignore file, but still, I think this isn't some random  
isolated problem that people never encounter.

While we're at it, can someone please explain to me how to remove a  
file from the index prior to the first commit? I'm stumped.

-masukomi

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bug] git-status shows bad instructions prior to first commit
  2008-02-12  0:59 [Bug] git-status shows bad instructions prior to first commit Rhodes, Kate
@ 2008-02-12  3:13 ` Junio C Hamano
  2008-02-12  5:45   ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2008-02-12  3:13 UTC (permalink / raw)
  To: Rhodes, Kate; +Cc: git

"Rhodes, Kate" <masukomi@gmail.com> writes:

> While we're at it, can someone please explain to me how to remove a
> file from the index prior to the first commit? I'm stumped.

rm --cached

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bug] git-status shows bad instructions prior to first commit
  2008-02-12  3:13 ` Junio C Hamano
@ 2008-02-12  5:45   ` Jeff King
  2008-02-13 22:02     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff King @ 2008-02-12  5:45 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Rhodes, Kate, git

On Mon, Feb 11, 2008 at 07:13:15PM -0800, Junio C Hamano wrote:

> "Rhodes, Kate" <masukomi@gmail.com> writes:
> 
> > While we're at it, can someone please explain to me how to remove a
> > file from the index prior to the first commit? I'm stumped.
> 
> rm --cached

And indeed, some clever person already made this distinction in the
git-status output, but it has been broken for a while. I'm not sure this
is worth a test now that it is fixed (but such a test _would_ have
caught this); I can make one if you like.

-- >8 --
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>
---
 wt-status.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/wt-status.c b/wt-status.c
index 27b946d..b5ae98d 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -60,7 +60,7 @@ static void wt_status_print_cached_header(struct wt_status *s)
 {
 	const char *c = color(WT_STATUS_HEADER);
 	color_fprintf_ln(s->fp, c, "# Changes to be committed:");
-	if (s->reference) {
+	if (!s->is_initial) {
 		color_fprintf_ln(s->fp, c, "#   (use \"git reset %s <file>...\" to unstage)", s->reference);
 	} else {
 		color_fprintf_ln(s->fp, c, "#   (use \"git rm --cached <file>...\" to unstage)");
-- 
1.5.4.1215.gf7da-dirty

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Bug] git-status shows bad instructions prior to first commit
  2008-02-12  5:45   ` Jeff King
@ 2008-02-13 22:02     ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2008-02-13 22:02 UTC (permalink / raw)
  To: Jeff King; +Cc: Rhodes, Kate, git

Jeff King <peff@peff.net> writes:

> 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.

In order to avoid regressing again, we must have something like
this included in your change, which I squashed in.

This goes to 'maint'.  Thanks for the fix.

 t/t7502-status.sh |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/t/t7502-status.sh b/t/t7502-status.sh
index 9ce50ca..b64ce30 100755
--- a/t/t7502-status.sh
+++ b/t/t7502-status.sh
@@ -17,6 +17,9 @@ test_expect_success 'setup' '
 	: > dir1/tracked &&
 	: > dir1/modified &&
 	git add . &&
+
+	git status >output &&
+
 	test_tick &&
 	git commit -m initial &&
 	: > untracked &&
@@ -28,6 +31,12 @@ test_expect_success 'setup' '
 	git add dir2/added
 '
 
+test_expect_success 'status (1)' '
+
+	grep -e "use \"git rm --cached <file>\.\.\.\" to unstage" output
+
+'
+
 cat > expect << \EOF
 # On branch master
 # Changes to be committed:
@@ -51,7 +60,7 @@ cat > expect << \EOF
 #	untracked
 EOF
 
-test_expect_success 'status' '
+test_expect_success 'status (2)' '
 
 	git status > output &&
 	git diff expect output

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-02-13 22:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-12  0:59 [Bug] git-status shows bad instructions prior to first commit Rhodes, Kate
2008-02-12  3:13 ` Junio C Hamano
2008-02-12  5:45   ` Jeff King
2008-02-13 22:02     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).