git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Kristian Høgsberg" <krh@redhat.com>,
	git@vger.kernel.org
Subject: Re: git-status producing incorrect results
Date: Thu, 14 Feb 2008 12:18:23 -0500	[thread overview]
Message-ID: <20080214171823.GA28762@coredump.intra.peff.net> (raw)
In-Reply-To: <alpine.LFD.1.00.0802140902470.6110@woody.linux-foundation.org>

On Thu, Feb 14, 2008 at 09:04:59AM -0800, Linus Torvalds wrote:

> ACK again, that's almost certainly the right long-term fix, but it 
> essentially requires a "copy_index()" thing that creates a new index from 
> an existing copy (so that we don't need to re-read it) etc infrastructure 
> changes, so I think your patch is the correct one for now.

Here is the cleaned-up mini-fix for now, then.

-- >8 --
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>
---
 builtin-commit.c  |    4 ++++
 t/t7502-status.sh |   21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/builtin-commit.c b/builtin-commit.c
index 0442c8e..6612b4f 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -317,6 +317,10 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)
 	if (write_cache(fd, active_cache, active_nr) ||
 	    close_lock_file(&false_lock))
 		die("unable to write temporary index file");
+
+	discard_cache();
+	read_cache_from(false_lock.filename);
+
 	return false_lock.filename;
 }
 
diff --git a/t/t7502-status.sh b/t/t7502-status.sh
index b64ce30..e006074 100755
--- a/t/t7502-status.sh
+++ b/t/t7502-status.sh
@@ -128,4 +128,25 @@ test_expect_success 'status without relative paths' '
 
 '
 
+cat <<EOF >expect
+# On branch master
+# Changes to be committed:
+#   (use "git reset HEAD <file>..." to unstage)
+#
+#	modified:   dir1/modified
+#
+# Untracked files:
+#   (use "git add <file>..." to include in what will be committed)
+#
+#	dir1/untracked
+#	dir2/
+#	expect
+#	output
+#	untracked
+EOF
+test_expect_success 'status of partial commit excluding new file in index' '
+	git status dir1/modified >output &&
+	diff -u expect output
+'
+
 test_done
-- 
1.5.4.1.1324.gfec5c

      reply	other threads:[~2008-02-14 17:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-14 16:45 git-status producing incorrect results Jeff King
2008-02-14 16:51 ` Johannes Schindelin
2008-02-14 16:54   ` Jeff King
2008-02-14 17:02     ` Johannes Schindelin
2008-02-14 17:02     ` Jeff King
2008-02-14 17:04 ` Linus Torvalds
2008-02-14 17:18   ` Jeff King [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080214171823.GA28762@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=krh@redhat.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).