docs/diff-options: clarify scope of diff-filter types
[gitweb.git] / t / t7800-difftool.sh
index 1c81f46cbf3b9a229c285afd13dfe627c95b7460..25241f40967ef1fb547771e64c69927de2f101ce 100755 (executable)
@@ -24,16 +24,15 @@ prompt_given ()
 }
 
 test_expect_success 'basic usage requires no repo' '
-       lines=$(git difftool -h | grep ^usage: | wc -l) &&
-       test "$lines" -eq 1 &&
+       test_expect_code 129 git difftool -h >output &&
+       grep ^usage: output &&
        # create a ceiling directory to prevent Git from finding a repo
        mkdir -p not/repo &&
-       ceiling="$PWD/not" &&
-       lines=$(cd not/repo &&
-               GIT_CEILING_DIRECTORIES="$ceiling" git difftool -h |
-               grep ^usage: | wc -l) &&
-       test "$lines" -eq 1 &&
-       rmdir -p not/repo
+       test_when_finished rm -r not &&
+       test_expect_code 129 \
+       env GIT_CEILING_DIRECTORIES="$(pwd)/not" \
+       git -C not/repo difftool -h >output &&
+       grep ^usage: output
 '
 
 # Create a file on master and change it on branch
@@ -291,8 +290,8 @@ test_expect_success 'difftool + mergetool config variables' '
 test_expect_success 'difftool.<tool>.path' '
        test_config difftool.tkdiff.path echo &&
        git difftool --tool=tkdiff --no-prompt branch >output &&
-       lines=$(grep file output | wc -l) &&
-       test "$lines" -eq 1
+       grep file output >grep-output &&
+       test_line_count = 1 grep-output
 '
 
 test_expect_success 'difftool --extcmd=cat' '
@@ -387,6 +386,7 @@ test_expect_success 'setup change in subdirectory' '
        echo master >sub/sub &&
        git add sub/sub &&
        git commit -m "added sub/sub" &&
+       git tag v1 &&
        echo test >>file &&
        echo test >>sub/sub &&
        git add file sub/sub &&
@@ -422,12 +422,56 @@ run_dir_diff_test 'difftool --dir-diff ignores --prompt' '
        grep file output
 '
 
-run_dir_diff_test 'difftool --dir-diff from subdirectory' '
+run_dir_diff_test 'difftool --dir-diff branch from subdirectory' '
        (
                cd sub &&
                git difftool --dir-diff $symlinks --extcmd ls branch >output &&
-               grep sub output &&
-               grep file output
+               # "sub" must only exist in "right"
+               # "file" and "file2" must be listed in both "left" and "right"
+               grep sub output > sub-output &&
+               test_line_count = 1 sub-output &&
+               grep file"$" output >file-output &&
+               test_line_count = 2 file-output &&
+               grep file2 output >file2-output &&
+               test_line_count = 2 file2-output
+       )
+'
+
+run_dir_diff_test 'difftool --dir-diff v1 from subdirectory' '
+       (
+               cd sub &&
+               git difftool --dir-diff $symlinks --extcmd ls v1 >output &&
+               # "sub" and "file" exist in both v1 and HEAD.
+               # "file2" is unchanged.
+               grep sub output >sub-output &&
+               test_line_count = 2 sub-output &&
+               grep file output >file-output &&
+               test_line_count = 2 file-output &&
+               ! grep file2 output
+       )
+'
+
+run_dir_diff_test 'difftool --dir-diff branch from subdirectory w/ pathspec' '
+       (
+               cd sub &&
+               git difftool --dir-diff $symlinks --extcmd ls branch -- .>output &&
+               # "sub" only exists in "right"
+               # "file" and "file2" must not be listed
+               grep sub output >sub-output &&
+               test_line_count = 1 sub-output &&
+               ! grep file output
+       )
+'
+
+run_dir_diff_test 'difftool --dir-diff v1 from subdirectory w/ pathspec' '
+       (
+               cd sub &&
+               git difftool --dir-diff $symlinks --extcmd ls v1 -- .>output &&
+               # "sub" exists in v1 and HEAD
+               # "file" is filtered out by the pathspec
+               grep sub output >sub-output &&
+               test_line_count = 2 sub-output &&
+               ! grep file output
        )
 '