{"thread":{"id":"18601","subject":"[PATCH] difftool: add support for a difftool.prompt config variable","startedAt":"2009-03-28T15:44:44Z","lastAt":"2009-03-28T15:44:44Z","messageCount":1,"participants":["David Aguilar"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"109714","messageId":"1238255084-90816-1-git-send-email-davvid@gmail.com","threadId":"18601","inReplyTo":null,"subject":"[PATCH] difftool: add support for a difftool.prompt config variable","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2009-03-28T15:44:44Z","receivedAt":"2009-03-28T15:44:44Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"difftool now supports difftool.prompt so that users do not have to\npass --no-prompt or hit enter each time a diff tool is launched.\nThe --prompt flag overrides the configuration variable.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n Documentation/config.txt       |    3 ++\n Documentation/git-difftool.txt |   10 +++++-\n git-difftool-helper.sh         |   10 +++++-\n git-difftool.perl              |   15 +++++++--\n t/t7800-difftool.sh            |   64 ++++++++++++++++++++++++++++++++++++++++\n 5 files changed, 96 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 089569a..81f9e9a 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -680,6 +680,9 @@ difftool.<tool>.cmd::\n \tis set to the name of the temporary file containing the contents\n \tof the diff post-image.\n \n+difftool.prompt::\n+\tPrompt before each invocation of the diff tool.\n+\n diff.wordRegex::\n \tA POSIX Extended Regular Expression used to determine what is a \"word\"\n \twhen performing word-by-word difference calculations.  Character\ndiff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt\nindex a00e943..73d4782 100644\n--- a/Documentation/git-difftool.txt\n+++ b/Documentation/git-difftool.txt\n@@ -7,7 +7,7 @@ git-difftool - Show changes using common diff tools\n \n SYNOPSIS\n --------\n-'git difftool' [--tool=<tool>] [-y|--no-prompt] [<'git diff' options>]\n+'git difftool' [--tool=<tool>] [-y|--no-prompt|--prompt] [<'git diff' options>]\n \n DESCRIPTION\n -----------\n@@ -21,6 +21,11 @@ OPTIONS\n --no-prompt::\n \tDo not prompt before launching a diff tool.\n \n+--prompt::\n+\tPrompt before each invocation of the diff tool.\n+\tThis is the default behaviour; the option is provided to\n+\toverride any configuration settings.\n+\n -t <tool>::\n --tool=<tool>::\n \tUse the diff tool specified by <tool>.\n@@ -72,6 +77,9 @@ difftool.<tool>.cmd::\n +\n See the `--tool=<tool>` option above for more details.\n \n+difftool.prompt::\n+\tPrompt before each invocation of the diff tool.\n+\n SEE ALSO\n --------\n linkgit:git-diff[1]::\ndiff --git a/git-difftool-helper.sh b/git-difftool-helper.sh\nindex b91002b..02bb135 100755\n--- a/git-difftool-helper.sh\n+++ b/git-difftool-helper.sh\n@@ -7,9 +7,15 @@\n #\n # Copyright (c) 2009 David Aguilar\n \n-# Set GIT_DIFFTOOL_NO_PROMPT to bypass the per-file prompt.\n+# difftool.prompt controls the default prompt/no-prompt behavior\n+# and is overridden with $GIT_DIFFTOOL*_PROMPT.\n should_prompt () {\n-\ttest -z \"$GIT_DIFFTOOL_NO_PROMPT\"\n+\tprompt=$(git config --bool difftool.prompt || echo true)\n+\tif test \"$prompt\" = true; then\n+\t\ttest -z \"$GIT_DIFFTOOL_NO_PROMPT\"\n+\telse\n+\t\ttest -n \"$GIT_DIFFTOOL_PROMPT\"\n+\tfi\n }\n \n # This function prepares temporary files and launches the appropriate\ndiff --git a/git-difftool.perl b/git-difftool.perl\nindex 8c160e5..985dfe0 100755\n--- a/git-difftool.perl\n+++ b/git-difftool.perl\n@@ -2,9 +2,12 @@\n # Copyright (c) 2009 David Aguilar\n #\n # This is a wrapper around the GIT_EXTERNAL_DIFF-compatible\n-# git-difftool-helper script.  This script exports\n-# GIT_EXTERNAL_DIFF and GIT_PAGER for use by git, and\n-# GIT_DIFFTOOL_NO_PROMPT and GIT_DIFF_TOOL for use by git-difftool-helper.\n+# git-difftool-helper script.\n+#\n+# This script exports GIT_EXTERNAL_DIFF and GIT_PAGER for use by git.\n+# GIT_DIFFTOOL_NO_PROMPT, GIT_DIFFTOOL_PROMPT, and GIT_DIFF_TOOL\n+# are exported for use by git-difftool-helper.\n+#\n # Any arguments that are unknown to this script are forwarded to 'git diff'.\n \n use strict;\n@@ -62,6 +65,12 @@ sub generate_command\n \t\t}\n \t\tif ($arg eq '-y' || $arg eq '--no-prompt') {\n \t\t\t$ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true';\n+\t\t\tdelete $ENV{GIT_DIFFTOOL_PROMPT};\n+\t\t\tnext;\n+\t\t}\n+\t\tif ($arg eq '--prompt') {\n+\t\t\t$ENV{GIT_DIFFTOOL_PROMPT} = 'true';\n+\t\t\tdelete $ENV{GIT_DIFFTOOL_NO_PROMPT};\n \t\t\tnext;\n \t\t}\n \t\tif ($arg eq '-h' || $arg eq '--help') {\ndiff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh\nindex ceef84b..9cb2790 100755\n--- a/t/t7800-difftool.sh\n+++ b/t/t7800-difftool.sh\n@@ -15,6 +15,7 @@ remove_config_vars()\n \t# Unset all config variables used by git-difftool\n \tgit config --unset diff.tool\n \tgit config --unset difftool.test-tool.cmd\n+\tgit config --unset difftool.prompt\n \tgit config --unset merge.tool\n \tgit config --unset mergetool.test-tool.cmd\n \treturn 0\n@@ -26,11 +27,18 @@ restore_test_defaults()\n \tremove_config_vars\n \tunset GIT_DIFF_TOOL\n \tunset GIT_MERGE_TOOL\n+\tunset GIT_DIFFTOOL_PROMPT\n \tunset GIT_DIFFTOOL_NO_PROMPT\n \tgit config diff.tool test-tool &&\n \tgit config difftool.test-tool.cmd 'cat $LOCAL'\n }\n \n+prompt_given()\n+{\n+\tprompt=\"$1\"\n+\ttest \"$prompt\" = \"Hit return to launch 'test-tool': branch\"\n+}\n+\n # Create a file on master and change it on branch\n test_expect_success 'setup' '\n \techo master >file &&\n@@ -116,6 +124,62 @@ test_expect_success 'GIT_DIFFTOOL_NO_PROMPT variable' '\n \trestore_test_defaults\n '\n \n+# git-difftool supports the difftool.prompt variable.\n+# Test that GIT_DIFFTOOL_PROMPT can override difftool.prompt = false\n+test_expect_success 'GIT_DIFFTOOL_PROMPT variable' '\n+\tgit config difftool.prompt false &&\n+\tGIT_DIFFTOOL_PROMPT=true &&\n+\texport GIT_DIFFTOOL_PROMPT &&\n+\n+\tprompt=$(echo | git difftool --prompt branch | tail -1) &&\n+\tprompt_given \"$prompt\" &&\n+\n+\trestore_test_defaults\n+'\n+\n+# Test that we don't have to pass --no-prompt when difftool.prompt is false\n+test_expect_success 'difftool.prompt config variable is false' '\n+\tgit config difftool.prompt false &&\n+\n+\tdiff=$(git difftool branch) &&\n+\ttest \"$diff\" = \"branch\" &&\n+\n+\trestore_test_defaults\n+'\n+\n+# Test that the -y flag can override difftool.prompt = true\n+test_expect_success 'difftool.prompt can overridden with -y' '\n+\tgit config difftool.prompt true &&\n+\n+\tdiff=$(git difftool -y branch) &&\n+\ttest \"$diff\" = \"branch\" &&\n+\n+\trestore_test_defaults\n+'\n+\n+# Test that the --prompt flag can override difftool.prompt = false\n+test_expect_success 'difftool.prompt can overridden with --prompt' '\n+\tgit config difftool.prompt false &&\n+\n+\tprompt=$(echo | git difftool --prompt branch | tail -1) &&\n+\tprompt_given \"$prompt\" &&\n+\n+\trestore_test_defaults\n+'\n+\n+# Test that the last flag passed on the command-line wins\n+test_expect_success 'difftool last flag wins' '\n+\tdiff=$(git difftool --prompt --no-prompt branch) &&\n+\ttest \"$diff\" = \"branch\" &&\n+\n+\trestore_test_defaults &&\n+\n+\tprompt=$(echo | git difftool --no-prompt --prompt branch | tail -1) &&\n+\tprompt_given \"$prompt\"\n+\n+\trestore_test_defaults\n+'\n+\n # git-difftool falls back to git-mergetool config variables\n # so test that behavior here\n test_expect_success 'difftool + mergetool config variables' '\n-- \n1.6.2.1.404.gb0085\n"}]}