Code

Merge branch 'jk/diff-m-doc'
[git.git] / t / t7800-difftool.sh
index 9bf6c98c54f368dfc837a8c5c374021269f20707..1de83ef98fdcbfd63469e66ba4886c2477b983ff 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (c) 2009 David Aguilar
+# Copyright (c) 2009, 2010 David Aguilar
 #
 
 test_description='git-difftool
@@ -15,6 +15,9 @@ if ! test_have_prereq PERL; then
        test_done
 fi
 
+LF='
+'
+
 remove_config_vars()
 {
        # Unset all config variables used by git-difftool
@@ -24,6 +27,7 @@ remove_config_vars()
        git config --unset difftool.prompt
        git config --unset merge.tool
        git config --unset mergetool.test-tool.cmd
+       git config --unset mergetool.prompt
        return 0
 }
 
@@ -32,7 +36,6 @@ restore_test_defaults()
        # Restores the test defaults used by several tests
        remove_config_vars
        unset GIT_DIFF_TOOL
-       unset GIT_MERGE_TOOL
        unset GIT_DIFFTOOL_PROMPT
        unset GIT_DIFFTOOL_NO_PROMPT
        git config diff.tool test-tool &&
@@ -89,6 +92,15 @@ test_expect_success 'difftool honors --gui' '
        restore_test_defaults
 '
 
+test_expect_success 'difftool --gui works without configured diff.guitool' '
+       git config diff.tool test-tool &&
+
+       diff=$(git difftool --no-prompt --gui branch) &&
+       test "$diff" = "branch" &&
+
+       restore_test_defaults
+'
+
 # Specify the diff tool using $GIT_DIFF_TOOL
 test_expect_success 'GIT_DIFF_TOOL variable' '
        git config --unset diff.tool
@@ -107,15 +119,7 @@ test_expect_success 'GIT_DIFF_TOOL overrides' '
        git config diff.tool bogus-tool &&
        git config merge.tool bogus-tool &&
 
-       GIT_MERGE_TOOL=test-tool &&
-       export GIT_MERGE_TOOL &&
-       diff=$(git difftool --no-prompt branch) &&
-       test "$diff" = "branch" &&
-       unset GIT_MERGE_TOOL &&
-
-       GIT_MERGE_TOOL=bogus-tool &&
        GIT_DIFF_TOOL=test-tool &&
-       export GIT_MERGE_TOOL &&
        export GIT_DIFF_TOOL &&
 
        diff=$(git difftool --no-prompt branch) &&
@@ -165,6 +169,17 @@ test_expect_success 'difftool.prompt config variable is false' '
        restore_test_defaults
 '
 
+# Test that we don't have to pass --no-prompt when mergetool.prompt is false
+test_expect_success 'difftool merge.prompt = false' '
+       git config --unset difftool.prompt
+       git config mergetool.prompt false &&
+
+       diff=$(git difftool branch) &&
+       test "$diff" = "branch" &&
+
+       restore_test_defaults
+'
+
 # Test that the -y flag can override difftool.prompt = true
 test_expect_success 'difftool.prompt can overridden with -y' '
        git config difftool.prompt true &&
@@ -223,7 +238,39 @@ test_expect_success 'difftool.<tool>.path' '
        diff=$(git difftool --tool=tkdiff --no-prompt branch) &&
        git config --unset difftool.tkdiff.path &&
        lines=$(echo "$diff" | grep file | wc -l) &&
-       test "$lines" -eq 1
+       test "$lines" -eq 1 &&
+
+       restore_test_defaults
+'
+
+test_expect_success 'difftool --extcmd=cat' '
+       diff=$(git difftool --no-prompt --extcmd=cat branch) &&
+       test "$diff" = branch"$LF"master
+'
+
+test_expect_success 'difftool --extcmd cat' '
+       diff=$(git difftool --no-prompt --extcmd cat branch) &&
+       test "$diff" = branch"$LF"master
+'
+
+test_expect_success 'difftool -x cat' '
+       diff=$(git difftool --no-prompt -x cat branch) &&
+       test "$diff" = branch"$LF"master
+'
+
+test_expect_success 'difftool --extcmd echo arg1' '
+       diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"echo\ \$1\" branch)
+       test "$diff" = file
+'
+
+test_expect_success 'difftool --extcmd cat arg1' '
+       diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$1\" branch)
+       test "$diff" = master
+'
+
+test_expect_success 'difftool --extcmd cat arg2' '
+       diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$2\" branch)
+       test "$diff" = branch
 '
 
 test_done