]> git.ipfire.org Git - thirdparty/git.git/commitdiff
difftool.c: learn a new way start at specified file
authorZheNing Hu <adlternative@gmail.com>
Fri, 19 Feb 2021 12:53:54 +0000 (12:53 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Feb 2021 21:35:49 +0000 (13:35 -0800)
`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 middle,
we will have to traverse list again to get the file diff which
we want to see. Therefore,teach the command an option
`--skip-to=<path>` to allow the user to say that diffs for earlier
paths are not interesting (because they were already seen in an
earlier session) and start this session with the named path.

Signed-off-by: ZheNing Hu <adlternative@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-difftool.txt
t/t7800-difftool.sh

index 484c485fd06c9d52e09b5e7324f5f13fd444e4f9..143b0c49d739aef285aab7b10a0c536257d5f6fc 100644 (file)
@@ -34,6 +34,14 @@ OPTIONS
        This is the default behaviour; the option is provided to
        override any configuration settings.
 
        This is the default behaviour; the option is provided to
        override any configuration settings.
 
+--rotate-to=<file>::
+       Start showing the diff for the given path,
+       the paths before it will move to end and output.
+
+--skip-to=<file>::
+       Start showing the diff for the given path, skipping all
+       the paths before it.
+
 -t <tool>::
 --tool=<tool>::
        Use the diff tool specified by <tool>.  Valid values include
 -t <tool>::
 --tool=<tool>::
        Use the diff tool specified by <tool>.  Valid values include
index 9192c141ffc618f70e15b7cf25883d55469e5c11..3e041e83aede07ead62d54cc9a9b485b8eaeda0f 100755 (executable)
@@ -762,4 +762,36 @@ test_expect_success 'difftool --gui, --tool and --extcmd are mutually exclusive'
        test_must_fail git difftool --gui --tool=test-tool --extcmd=cat
 '
 
        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_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_expect_success 'difftool --rotate/skip-to error condition' '
+       test_must_fail git difftool --no-prompt --extcmd=cat --rotate-to="3" HEAD^ &&
+       test_must_fail git difftool --no-prompt --extcmd=cat --skip-to="3" HEAD^
+'
 test_done
 test_done