From: Jeff King <peff@peff.net>
To: "Carlos Martín Nieto" <cmn@elego.de>, git@vger.kernel.org
Subject: Re: reset reports file as modified when it's in fact deleted
Date: Mon, 7 Nov 2011 11:26:42 -0500 [thread overview]
Message-ID: <20111107162642.GA27055@sigill.intra.peff.net> (raw)
In-Reply-To: <20111107094330.GB10936@beez.lab.cmartin.tk>
On Mon, Nov 07, 2011 at 10:43:30AM +0100, Carlos Martín Nieto wrote:
> When I delete a file (git rm) and then reset so it exists in the index
> again, the message tells me 'M file.txt' even though the file doesn't
> exist in the worktree anymore. Running git status afterwards does give
> the correct output. So, here's the minimal steps to reproduce:
>
> $ git init
> Initialized empty Git repository in /home/carlos/test/reset-err/.git/
> $ touch file.txt
> $ git add file.txt
> $ git ci file.txt -m initial
> [master (root-commit) a536393] initial
> 0 files changed, 0 insertions(+), 0 deletions(-)
> create mode 100644 file.txt
> $ git rm file.txt
> rm 'file.txt'
> $ git reset -- file.txt
> Unstaged changes after reset:
> M file.txt
> $ git status -b -s
> ## master
> D file.txt
You can simplify this even further by not touching the index at all:
git init -q &&
>file && git add file && git commit -q -m initial &&
rm file &&
git reset
produces:
Unstaged changes after reset:
M file
> I'd expect the output after "Unstaged changes after reset" to tell me
> file.txt has been deleted instead of modified. This happens with
> 1.7.8-rc0, 1.7.7 and 1.7.4.1 and I expect with many more that I don't
> have here.
>
> I thought the index diff code might have been checking the index at the
> wrong time, but I can run 'git reset HEAD -- file.txt' as many times
> as I want, and it will still say 'M', so now I'm not sure.
The index diff code isn't running at all. Those messages are produced by
refresh_index, which outputs only two flags: modified or unmerged. I
think the reason for this is somewhat historical. You would run
"update-index --refresh", and it would helpfully say "by the way, when
refreshing this entry, I noticed that it is in need of being updated in
the index". The text was "file.txt: needs update".
Later, many porcelain commands started to refresh the index themselves,
and the "needs update" message was very confusing. So it was switched to
the more familiar "M file.txt" (though you can still see the original
plumbing message if you run update-index yourself).
I think it is a little more friendly to distinguish deletion from just
modification. And there's shouldn't be any compatibility questions, as
these are explicitly porcelain output (plumbing will still say "needs
update").
There are a few other cases users might expect to see. We'll never show
copies or renames, of course, because we aren't actually doing a diff
with copy detection. We won't see an "A"dded file, because such a file
would be in the working tree but not the index, meaning it is not
tracked.
We could see a "T"ypechange, but the distinction between that and a
modified file is lost by the time we get to refresh_index. We could pass
it up, but I wonder if it's really worth it.
The patch to do "D"eleted is pretty simple:
diff --git a/read-cache.c b/read-cache.c
index dea7cd8..cc1ebdf 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1103,9 +1103,11 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
int in_porcelain = (flags & REFRESH_IN_PORCELAIN);
unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0;
const char *needs_update_fmt;
+ const char *needs_rm_fmt;
const char *needs_merge_fmt;
needs_update_fmt = (in_porcelain ? "M\t%s\n" : "%s: needs update\n");
+ needs_rm_fmt = (in_porcelain ? "D\t%s\n" : "%s: needs update\n");
needs_merge_fmt = (in_porcelain ? "U\t%s\n" : "%s: needs merge\n");
for (i = 0; i < istate->cache_nr; i++) {
struct cache_entry *ce, *new;
@@ -1145,7 +1147,10 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
}
if (quiet)
continue;
- show_file(needs_update_fmt, ce->name, in_porcelain, &first, header_msg);
+ if (cache_errno == ENOENT)
+ show_file(needs_rm_fmt, ce->name, in_porcelain, &first, header_msg);
+ else
+ show_file(needs_update_fmt, ce->name, in_porcelain, &first, header_msg);
has_errors = 1;
continue;
}
next prev parent reply other threads:[~2011-11-07 16:26 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-07 9:43 reset reports file as modified when it's in fact deleted Carlos Martín Nieto
2011-11-07 16:26 ` Jeff King [this message]
2011-11-11 14:08 ` Carlos Martín Nieto
2011-11-11 16:43 ` Junio C Hamano
2011-11-11 18:21 ` Jeff King
2011-11-12 0:11 ` Junio C Hamano
2011-11-14 22:50 ` Jeff King
2011-11-14 22:51 ` [PATCH 1/4] refresh_index: rename format variables Jeff King
2011-11-14 22:52 ` [PATCH 2/4] refresh_index: mark deletions in porcelain output Jeff King
2011-11-14 22:52 ` [PATCH 3/4] read-cache: let refresh_cache_ent pass up changed flags Jeff King
2011-11-14 22:56 ` [PATCH 4/4] refresh_index: notice typechanges in output Jeff King
2011-11-15 0:08 ` Junio C Hamano
2011-11-15 2:05 ` Jeff King
2011-11-18 11:09 ` Jeff King
2011-11-18 11:11 ` [PATCHv2 1/3] read-cache: let refresh_cache_ent pass up changed flags Jeff King
2011-11-18 11:11 ` [PATCHv2 2/3] refresh_index: rename format variables Jeff King
2011-11-18 11:13 ` [PATCH 3/3] refresh_index: make porcelain output more specific Jeff King
2011-11-18 20:40 ` [PATCH 4/4] refresh_index: notice typechanges in output Junio C Hamano
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=20111107162642.GA27055@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=cmn@elego.de \
--cc=git@vger.kernel.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).