From: ZheNing Hu <adlternative@xxxxxxxxx> `git difftool` only allow us to select file to view in turn. If there is a commit with many files and we exit in the search, We will have to traverse list again to get the file diff which we want to see. Therefore, here is a new method: user can use `git difftool --rotate-to=<filename>` or `git difftool --skip-to=<filename>` to start viewing from the specified file, This will improve the user experience. `git difftool --rotate-to=<file>` or `git difftool --skip-to=<filename>` will pass the path to `diffcore-rotate`, and diff-core will adjust the order of files, make the specified file sorted to the first.`git difftool --rotate-to=<file>` will move files before the specified path to the last output, and `git difftool --skip-to=<filename>` will ignore these files output. It is an error when there is no patch for specified file is shown. Signed-off-by: ZheNing Hu <adlternative@xxxxxxxxx> --- Documentation/diff-options.txt | 2 +- Documentation/git-difftool.txt | 10 ++++++++++ t/t7800-difftool.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index 7c5b3cf42bcc..aa2b5c11f20b 100644 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@ -701,7 +701,7 @@ components matches the pattern. For example, the pattern "`foo*bar`" matches "`fooasdfbar`" and "`foo/bar/baz/asdf`" but not "`foobarx`". --skip-to=<file>:: ---rotate-to=<file:: +--rotate-to=<file>:: Discard the files before the named <file> from the output (i.e. 'skip to'), or move them to the end of the output (i.e. 'rotate to'). These were invented primarily for use diff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt index 484c485fd06c..c64dff69c976 100644 --- a/Documentation/git-difftool.txt +++ b/Documentation/git-difftool.txt @@ -34,6 +34,16 @@ OPTIONS This is the default behaviour; the option is provided to override any configuration settings. +--rotate-to=<file>:: + Internally call `git diff --rotate-to=<file>`, + show the change in the specified path first. + Files before the specified path will be moved to the last output. + +--skip-to=<file>:: + Internally call `git diff --skip-to=<file>`, + skip the output to the specified path. + Files before the specified path will not output. + -t <tool>:: --tool=<tool>:: Use the diff tool specified by <tool>. Valid values include diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 9192c141ffc6..112b798b1c23 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -762,4 +762,34 @@ test_expect_success 'difftool --gui, --tool and --extcmd are mutually exclusive' test_must_fail git difftool --gui --tool=test-tool --extcmd=cat ' +test_expect_success 'difftool --rotate-to' ' + difftool_test_setup && + test_when_finished git reset --hard && + echo 1 >1 && + echo 2 >2 && + echo 4 >4 && + git add 1 2 4 && + git commit -a -m "124" && + git difftool --no-prompt --extcmd=cat --rotate-to="2" HEAD^ >output&& + cat >expect <<-\EOF && + 2 + 4 + 1 + EOF + test_cmp output expect && + test_must_fail git difftool --no-prompt --extcmd=cat --rotate-to="3" HEAD^ +' + +test_expect_success 'difftool --skip-to' ' + difftool_test_setup && + test_when_finished git reset --hard && + git difftool --no-prompt --extcmd=cat --skip-to="2" HEAD^ >output && + cat >expect <<-\EOF && + 2 + 4 + EOF + test_cmp output expect && + test_must_fail git difftool --no-prompt --extcmd=cat --skip-to="3" HEAD^ +' + test_done -- gitgitgadget