git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* BUG?: git diff with 3 args consults work tree when it shouldn't
@ 2011-08-01 17:35 Johan Herland
  2011-08-04  2:54 ` Re* " Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Johan Herland @ 2011-08-01 17:35 UTC (permalink / raw)
  To: git

Hi,

I'm viewing the combined diff of a merge commit where the correct 
resolution involved the removal of a conflicting file. In short, the 
(simplified) scenario is:

    A
   / \
  O   M
   \ /
    B

where commit O does not contain the file, branches A and B add 
conflicting versions of the file, and merge M removes the file (see 
below for a full command session illustrating the scenario).

When I view the combined diff of the merge (using "git diff M A B" or 
"git show M" ), it seems the resulting diff depends on the 
existence/contents of the file in my *current work tree*. I.e. if I 
checkout O or M (where the file is missing) before producing the diff, 
the result seems correct, but if I put a garbage version of the file in 
my work tree (without adding or committing it at all), the garbage shows 
up in the diff, as follows:

  $ git diff M A B
  diff --cc file
  index 34b6a0c,732c85a..0000000
  --- a/file
  +++ b/file
  @@@ -1,1 -1,1 +1,1 @@@
  - contents contributed by A
   -contents contributed by B
  ++garbage contents from my work tree

AFAICS, when producing combined diffs, the diff code should not look up 
the file in the current work tree, since the diff arguments refer to 
existing commits, and do not indicate that the work tree should be 
consulted at all.


...Johan


Example session illustrating the problem:

$ git init repo
Initialized empty Git repository in ./repo/.git/
$ cd repo
$ echo foo > foo
$ git add foo
$ git commit -m foo
[master (root-commit) c6d62c2] foo
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 foo
$ git checkout -b a
Switched to a new branch 'a'
$ echo spam > file
$ git add file
$ git commit -m spam
[a d2d3128] spam
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 file
$ git checkout -b b master
Switched to a new branch 'b'
$ echo eggs > file
$ git add file
$ git commit -m eggs
[b 72e8252] eggs
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 file
$ git checkout -b m
Switched to a new branch 'm'
$ git merge a
Auto-merging file
CONFLICT (add/add): Merge conflict in file
Automatic merge failed; fix conflicts and then commit the result.
$ git rm file
file: needs merge
rm 'file'
$ git commit -m merge
[m c096356] merge
$ git diff m a b
diff --cc file
index 34b6a0c,732c85a..0000000
deleted file mode 100644,100644
--- a/file
+++ /dev/null
$ ### HERE IS WHERE IT GOES WRONG:
$ echo xyzzy > file
$ git diff m a b
diff --cc file
index 34b6a0c,732c85a..0000000
--- a/file
+++ b/file
@@@ -1,1 -1,1 +1,1 @@@
- spam
 -eggs
++xyzzy



-- 
Johan Herland, <johan@herland.net>
www.herland.net

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

end of thread, other threads:[~2011-08-04 18:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-01 17:35 BUG?: git diff with 3 args consults work tree when it shouldn't Johan Herland
2011-08-04  2:54 ` Re* " Junio C Hamano
2011-08-04 18:58   ` [PATCH] diff -c/--cc: do not mistake "resolved as deletion" as "use working tree" 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).