difftool: handle unmerged files in dir-diff mode
authorDavid Aguilar <davvid@gmail.com>
Mon, 16 May 2016 18:05:37 +0000 (11:05 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 May 2016 21:53:05 +0000 (14:53 -0700)
When files are unmerged they can show up as both unmerged and
modified in the output of `git diff --raw`. This causes
difftool's dir-diff to create filesystem entries for the same
path twice, which fails when it encounters a duplicate path.

Ensure that each worktree path is only processed once.
Add a test to demonstrate the breakage.

Reported-by: Jan Smets <jan@smets.cx>
Signed-off-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-difftool.perl
t/t7800-difftool.sh
index 8cf0040590645fedca47e25a9167511e7c27c8e9..ebd13baa6e06cf7007fdd5c48713f06cf511721d 100755 (executable)
@@ -138,6 +138,7 @@ sub setup_dir_diff
        my %submodule;
        my %symlink;
        my @working_tree = ();
        my %submodule;
        my %symlink;
        my @working_tree = ();
+       my %working_tree_dups = ();
        my @rawdiff = split('\0', $diffrtn);
 
        my $i = 0;
        my @rawdiff = split('\0', $diffrtn);
 
        my $i = 0;
@@ -188,6 +189,10 @@ sub setup_dir_diff
                }
 
                if ($rmode ne $null_mode) {
                }
 
                if ($rmode ne $null_mode) {
+                       # Avoid duplicate working_tree entries
+                       if ($working_tree_dups{$dst_path}++) {
+                               next;
+                       }
                        my ($use, $wt_sha1) = use_wt_file($repo, $workdir,
                                                          $dst_path, $rsha1);
                        if ($use) {
                        my ($use, $wt_sha1) = use_wt_file($repo, $workdir,
                                                          $dst_path, $rsha1);
                        if ($use) {
index 4e713f7aa54d4713cfd74978460ec9aa144fc773..6a7207b9506d76beed912698be63afffcd503991 100755 (executable)
@@ -419,6 +419,29 @@ run_dir_diff_test 'difftool --dir-diff when worktree file is missing' '
        grep file2 output
 '
 
        grep file2 output
 '
 
+run_dir_diff_test 'difftool --dir-diff with unmerged files' '
+       test_when_finished git reset --hard &&
+       test_config difftool.echo.cmd "echo ok" &&
+       git checkout -B conflict-a &&
+       git checkout -B conflict-b &&
+       git checkout conflict-a &&
+       echo a >>file &&
+       git add file &&
+       git commit -m conflict-a &&
+       git checkout conflict-b &&
+       echo b >>file &&
+       git add file &&
+       git commit -m conflict-b &&
+       git checkout master &&
+       git merge conflict-a &&
+       test_must_fail git merge conflict-b &&
+       cat >expect <<-EOF &&
+               ok
+       EOF
+       git difftool --dir-diff $symlinks -t echo >actual &&
+       test_cmp expect actual
+'
+
 write_script .git/CHECK_SYMLINKS <<\EOF
 for f in file file2 sub/sub
 do
 write_script .git/CHECK_SYMLINKS <<\EOF
 for f in file file2 sub/sub
 do