{"thread":{"id":"44638","subject":"[PATCH v2] difftool: fix dir-diff index creation when in a subdirectory","startedAt":"2016-12-07T10:16:19Z","lastAt":"2016-12-12T21:35:50Z","messageCount":2,"participants":["David Aguilar","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"307100","messageId":"20161207101608.16058-1-davvid@gmail.com","threadId":"44638","inReplyTo":null,"subject":"[PATCH v2] difftool: fix dir-diff index creation when in a subdirectory","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2016-12-07T10:16:08Z","receivedAt":"2016-12-07T10:16:19Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"9ec26e7977 (difftool: fix argument handling in subdirs, 2016-07-18)\ncorrected how path arguments are handled in a subdirectory, but\nit introduced a regression in how entries outside of the\nsubdirectory are handled by dir-diff.\n\nWhen preparing the right-side of the diff we only include the\nchanged paths in the temporary area.\n\nThe left side of the diff is constructed from a temporary\nindex that is built from the same set of changed files, but it\nwas being constructed from within the subdirectory.  This is a\nproblem because the indexed paths are toplevel-relative, and\nthus they were not getting added to the index.\n\nTeach difftool to chdir to the toplevel of the repository before\npreparing its temporary indexes.  This ensures that all of the\ntoplevel-relative paths are valid.\n\nAdd test cases to more thoroughly exercise this scenario.\n\nReported-by: Frank Becker <fb@mooflu.com>\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\nChanges since v1:\n\n- Improved commit message thanks to Johannes Schindelin\n  (\"git whatis\" was used to describe the referenced commit)\n\n- Add more tests for edge cases that are properly handled\n  but were not being tested.\n\n git-difftool.perl   |  4 ++++\n t/t7800-difftool.sh | 44 +++++++++++++++++++++++++++++++++++++++++---\n 2 files changed, 45 insertions(+), 3 deletions(-)\n\ndiff --git a/git-difftool.perl b/git-difftool.perl\nindex a5790d03a0..959822d5f3 100755\n--- a/git-difftool.perl\n+++ b/git-difftool.perl\n@@ -182,6 +182,10 @@ EOF\n \t\t}\n \t}\n \n+\t# Go to the root of the worktree so that the left index files\n+\t# are properly setup -- the index is toplevel-relative.\n+\tchdir($workdir);\n+\n \t# Setup temp directories\n \tmy $tmpdir = tempdir('git-difftool.XXXXX', CLEANUP => 0, TMPDIR => 1);\n \tmy $ldir = \"$tmpdir/left\";\ndiff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh\nindex 70a2de461a..99d4123461 100755\n--- a/t/t7800-difftool.sh\n+++ b/t/t7800-difftool.sh\n@@ -374,6 +374,7 @@ test_expect_success PERL 'setup change in subdirectory' '\n \techo master >sub/sub &&\n \tgit add sub/sub &&\n \tgit commit -m \"added sub/sub\" &&\n+\tgit tag v1 &&\n \techo test >>file &&\n \techo test >>sub/sub &&\n \tgit add file sub/sub &&\n@@ -409,12 +410,49 @@ run_dir_diff_test 'difftool --dir-diff ignores --prompt' '\n \tgrep file output\n '\n \n-run_dir_diff_test 'difftool --dir-diff from subdirectory' '\n+run_dir_diff_test 'difftool --dir-diff branch from subdirectory' '\n \t(\n \t\tcd sub &&\n \t\tgit difftool --dir-diff $symlinks --extcmd ls branch >output &&\n-\t\tgrep sub output &&\n-\t\tgrep file output\n+\t\t# \"sub\" must only exist in \"right\"\n+\t\t# \"file\" and \"file2\" must be listed in both \"left\" and \"right\"\n+\t\ttest \"1\" = $(grep sub output | wc -l) &&\n+\t\ttest \"2\" = $(grep file\"$\" output | wc -l) &&\n+\t\ttest \"2\" = $(grep file2 output | wc -l)\n+\t)\n+'\n+\n+run_dir_diff_test 'difftool --dir-diff v1 from subdirectory' '\n+\t(\n+\t\tcd sub &&\n+\t\tgit difftool --dir-diff $symlinks --extcmd ls v1 >output &&\n+\t\t# \"sub\" and \"file\" exist in both v1 and HEAD.\n+\t\t# \"file2\" is unchanged.\n+\t\ttest \"2\" = $(grep sub output | wc -l) &&\n+\t\ttest \"2\" = $(grep file output | wc -l) &&\n+\t\ttest \"0\" = $(grep file2 output | wc -l)\n+\t)\n+'\n+\n+run_dir_diff_test 'difftool --dir-diff branch from subdirectory w/ pathspec' '\n+\t(\n+\t\tcd sub &&\n+\t\tgit difftool --dir-diff $symlinks --extcmd ls branch -- .>output &&\n+\t\t# \"sub\" only exists in \"right\"\n+\t\t# \"file\" and \"file2\" must not be listed\n+\t\ttest \"1\" = $(grep sub output | wc -l) &&\n+\t\ttest \"0\" = $(grep file output | wc -l)\n+\t)\n+'\n+\n+run_dir_diff_test 'difftool --dir-diff v1 from subdirectory w/ pathspec' '\n+\t(\n+\t\tcd sub &&\n+\t\tgit difftool --dir-diff $symlinks --extcmd ls v1 -- .>output &&\n+\t\t# \"sub\" exists in v1 and HEAD\n+\t\t# \"file\" is filtered out by the pathspec\n+\t\ttest \"2\" = $(grep sub output | wc -l) &&\n+\t\ttest \"0\" = $(grep file output | wc -l)\n \t)\n '\n \n-- \n2.11.0.1.g7697df0\n\n"},{"id":"307549","messageId":"xmqqk2b496fk.fsf@gitster.mtv.corp.google.com","threadId":"44638","inReplyTo":"20161207101608.16058-1-davvid@gmail.com","subject":"Re: [PATCH v2] difftool: fix dir-diff index creation when in a subdirectory","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-12-12T21:35:43Z","receivedAt":"2016-12-12T21:35:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks; queued and pushed out together with the follow-up series.\n"}]}