difftool: don't overwrite modified files
commit67aa147af7c699348ba8c3afe9f7ee88aa043cd0
authorJohn Keeping <john@keeping.me.uk>
Fri, 29 Mar 2013 22:07:39 +0000 (29 22:07 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 29 Mar 2013 22:16:04 +0000 (29 15:16 -0700)
tree87e429a84f736752799aea0e8e0ecc25ce732a67
parentbf341b902ea1346373886f4eb4352a06b7b4cdfd
difftool: don't overwrite modified files

After running the user's diff tool, git-difftool will copy any files
that differ between the working tree and the temporary tree.  This is
useful when the user edits the file in their diff tool but is wrong if
they edit the working tree file while examining the diff.

Instead of copying unconditionally when the files differ, create and
index from the working tree files and only copy the temporary file back
if it was modified and the working tree file was not.  If both files
have been modified, print a warning and exit with an error.

Note that we cannot use an existing index in git-difftool since those
contain the modified files that need to be checked out but here we are
looking at those files which are copied from the working tree and not
checked out.  These are precisely the files which are not in the
existing indices.

Signed-off-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-difftool.perl
t/t7800-difftool.sh