Skip to content

Commit 1c88102

Browse files
adlternativegitster
authored andcommitted
difftool.c: learn a new way start at specified file
`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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1eb4136 commit 1c88102

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

Documentation/git-difftool.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ OPTIONS
3434
This is the default behaviour; the option is provided to
3535
override any configuration settings.
3636

37+
--rotate-to=<file>::
38+
Start showing the diff for the given path,
39+
the paths before it will move to end and output.
40+
41+
--skip-to=<file>::
42+
Start showing the diff for the given path, skipping all
43+
the paths before it.
44+
3745
-t <tool>::
3846
--tool=<tool>::
3947
Use the diff tool specified by <tool>. Valid values include

t/t7800-difftool.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,4 +762,36 @@ test_expect_success 'difftool --gui, --tool and --extcmd are mutually exclusive'
762762
test_must_fail git difftool --gui --tool=test-tool --extcmd=cat
763763
'
764764

765+
test_expect_success 'difftool --rotate-to' '
766+
difftool_test_setup &&
767+
test_when_finished git reset --hard &&
768+
echo 1 >1 &&
769+
echo 2 >2 &&
770+
echo 4 >4 &&
771+
git add 1 2 4 &&
772+
git commit -a -m "124" &&
773+
git difftool --no-prompt --extcmd=cat --rotate-to="2" HEAD^ >output&&
774+
cat >expect <<-\EOF &&
775+
2
776+
4
777+
1
778+
EOF
779+
test_cmp output expect
780+
'
781+
782+
test_expect_success 'difftool --skip-to' '
783+
difftool_test_setup &&
784+
test_when_finished git reset --hard &&
785+
git difftool --no-prompt --extcmd=cat --skip-to="2" HEAD^ >output &&
786+
cat >expect <<-\EOF &&
787+
2
788+
4
789+
EOF
790+
test_cmp output expect
791+
'
792+
793+
test_expect_success 'difftool --rotate/skip-to error condition' '
794+
test_must_fail git difftool --no-prompt --extcmd=cat --rotate-to="3" HEAD^ &&
795+
test_must_fail git difftool --no-prompt --extcmd=cat --skip-to="3" HEAD^
796+
'
765797
test_done

0 commit comments

Comments
 (0)