emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Git conflict VC state detection


From: Dmitry Gutov
Subject: Re: Git conflict VC state detection
Date: Tue, 12 Nov 2013 01:16:45 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0

On 11.11.2013 00:19, Óscar Fuentes wrote:
Dmitry Gutov <address@hidden> writes:

On 10.11.2013 22:30, Óscar Fuentes wrote:
I've revised the initial commit implementing conflict state detection on
my private branch and the problem with it was that it didn't detect
edited state on a staged file, i.e. a file containing staged (but
uncommitted) changes would show as up to date.

So I pursued a more precise method. The problem is that the git commands
that tells you that a file is unmerged doesn't tell that a file contains
changes if those are staged.

Are you sure? AFAICS, 'git diff' behaves this way ('git diff' shows
only unstages changes, 'git diff --cached' only stages ones, but 'git
diff HEAD' will include both), but the 'git diff-index' command we're
using already includes HEAD as the reference, and even if I do a 'git
add' on some edited file, while 'git diff' shows me nothing, 'git
diff-index --raw HEAD' includes the file with status M.

I haven't tested it in the situation with a file being merged, though.
Maybe that's different somehow.

With the current method in vc-git-state, this is an example where
the file keyword.cpp is unmerged:

$ git diff-index HEAD -- keyword.cpp

(-p --raw options eluded, as they just add the patch to the output,
which is useless.)

:100644 100644 12b8b5a24d99dfec20c4b5283d91b15ed1a83b4e 
0000000000000000000000000000000000000000 Mkeyword.cpp

At first, you can think that those series of zeroes mean something (the
documentation for git-diff-index says

``sha1 for "dst"; 0{40} if creation, unmerged or "look at work tree"

which is quite vague) so let's try with a plainly edited file:

$ git diff-index HEAD -- CMakeLists.txt

:100644 100644 8465aca146db66862498b9e2f2a8993e5d8dda69 
0000000000000000000000000000000000000000 MCMakeLists.txt

Hence `git diff-index' can't tell the difference among an unmerged and
an edited file.

I see.

Now let's try again but with the `--cached' option:

$ git diff-index --cached -- keyword.cpp

:100644 000000 12b8b5a24d99dfec20c4b5283d91b15ed1a83b4e 
0000000000000000000000000000000000000000 Ukeyword.cpp

There it is the `U'. But with the edited, unstaged file:

$ git diff-index --cached HEAD -- CMakeLists.txt

<no output>

And then you need a plain "git diff-index HEAD -- CMakeLists.txt" for
knowing that the file is edited.

AFAIK there is no command that tells that a file is unmerged and also
tells that it is edited, no matter if its changes are staged or not.

Your example tells me that if 'git diff-index --cached' returns status 'U', then plain 'git diff-index' has to return status 'M', doesn't it?

IOW, if you call the command without '--cached' first, you can avoid the second invocation if the status is not 'M'.

Or, better yet, also check for diff3 markers, like Stefan suggested.

I CC'ed Dmitry as he implemented the part that my patch touches. I'll
like to get the ok from him before installing the patch,

I did a relatively small change there, actually, it just unwrapped all
the code in `vc-git-registered'.

So you were wrongly "blamed" :-) Sorry about that.

Not a problem.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]