{"thread":{"id":"30026","subject":"[PATCH 10/9 v5] difftool: fix regression in '--prompt' options","startedAt":"2012-03-22T15:02:19Z","lastAt":"2012-03-22T15:02:21Z","messageCount":3,"participants":["Tim Henigan"],"isPatch":true,"patchVersion":5,"patchTotal":9},"messages":[{"id":"187472","messageId":"1332428541-24878-1-git-send-email-tim.henigan@gmail.com","threadId":"30026","inReplyTo":null,"subject":"[PATCH 10/9 v5] difftool: fix regression in '--prompt' options","fromName":"Tim Henigan","fromEmail":"tim.henigan@gmail.com","sentAt":"2012-03-22T15:02:19Z","receivedAt":"2012-03-22T15:02:19Z","isPatch":true,"sender":{"key":"tim.henigan@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42022?v=4"},"body":"When difftool was changed to use Getopt::Long, it changed the way\nthat the '--prompt' and '--no-prompt' options were handled. The\nexpected behavior is that the two options may be given any number\nof times. The last option given \"wins\".\n\nFor example, if a user sets \"[alias] mdt = difftool --prompt\", the\nfollowing must still run without error:\n\n$ git mdt --no-prompt\n\nThe changes made during the switch to Getopt::Long broke this\nbehavior. This commit teaches difftool to handle them properly\nagain.\n\nSigned-off-by: Tim Henigan <tim.henigan@gmail.com>\n---\n\nThis replaces 10/9 in the previous version of the series.\n\nChanges in v5:\n  - Based on an example provided by Thomas Rast on the Git dev list,\n    the '--[no-]prompt' options are parsed by Getopt::Long again.\n\n\n git-difftool.perl |   21 +++++++++++----------\n 1 file changed, 11 insertions(+), 10 deletions(-)\n\ndiff --git a/git-difftool.perl b/git-difftool.perl\nindex 9f0f9a9..9892d1e 100755\n--- a/git-difftool.perl\n+++ b/git-difftool.perl\n@@ -29,8 +29,8 @@ sub usage\n \tmy $exitcode = shift;\n \tprint << 'USAGE';\n usage: git difftool [-t|--tool=<tool>] [--tool-help]\n-                    [-x|--extcmd=<cmd>]\n-                    [-y|--no-prompt]   [-g|--gui]\n+                    [-x|--extcmd=<cmd>] [-g|--gui]\n+                    [--prompt] [-y|--no-prompt]\n                     [-d|--dir-diff]\n                     ['git diff' options]\n USAGE\n@@ -131,15 +131,15 @@ sub setup_dir_diff\n \n # parse command-line options. all unrecognized options and arguments\n # are passed through to the 'git diff' command.\n-my ($difftool_cmd, $dirdiff, $extcmd, $gui, $help, $no_prompt, $prompt, $tool_help);\n+my ($difftool_cmd, $dirdiff, $extcmd, $gui, $help, $prompt, $tool_help);\n GetOptions('g|gui' => \\$gui,\n \t'd|dir-diff' => \\$dirdiff,\n \t'h' => \\$help,\n-\t'prompt' => \\$prompt,\n+\t'prompt!' => \\$prompt,\n+\t'y' => sub { $prompt = 0; },\n \t't|tool:s' => \\$difftool_cmd,\n \t'tool-help' => \\$tool_help,\n-\t'x|extcmd:s' => \\$extcmd,\n-\t'y|no-prompt' => \\$no_prompt);\n+\t'x|extcmd:s' => \\$extcmd);\n \n if (defined($help)) {\n \tusage(0);\n@@ -203,10 +203,11 @@ if (defined($dirdiff)) {\n \t}\n } else {\n \tif (defined($prompt)) {\n-\t\t$ENV{GIT_DIFFTOOL_PROMPT} = 'true';\n-\t}\n-\telsif (defined($no_prompt)) {\n-\t\t$ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true';\n+\t\tif ($prompt) {\n+\t\t\t$ENV{GIT_DIFFTOOL_PROMPT} = 'true';\n+\t\t} else {\n+\t\t\t$ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true';\n+\t\t}\n \t}\n \n \t$ENV{GIT_PAGER} = '';\n-- \n1.7.10.rc1.40.g756bbcd\n"},{"id":"187473","messageId":"1332428541-24878-2-git-send-email-tim.henigan@gmail.com","threadId":"30026","inReplyTo":"1332428541-24878-1-git-send-email-tim.henigan@gmail.com","subject":"[PATCH 12/9 v5] t7800: add tests for difftool --dir-diff","fromName":"Tim Henigan","fromEmail":"tim.henigan@gmail.com","sentAt":"2012-03-22T15:02:20Z","receivedAt":"2012-03-22T15:02:20Z","isPatch":true,"sender":{"key":"tim.henigan@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42022?v=4"},"body":"Signed-off-by: Tim Henigan <tim.henigan@gmail.com>\n---\n\nThis replaces 12/9 in the previous version of the series.\n\nChanges in v5:\n\nBased on an example provided by David Aguilar on the Git developer\nlist, the 'difftool --dir-diff from subdirectory' test is now wrapped\nin parentheses \"()\".\n\n>From David's email:\n> If we wrap the subdir operations in parentheses, then the sub-shell\n> saves us from having to do \"cd ..\".  It also helps prevent leakage\n> from earlier failures, which is helpful when writing new tests.\n\n\n t/t7800-difftool.sh |   39 +++++++++++++++++++++++++++++++++++++++\n 1 file changed, 39 insertions(+)\n\ndiff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh\nindex 41d8399..5f3ad3f 100755\n--- a/t/t7800-difftool.sh\n+++ b/t/t7800-difftool.sh\n@@ -311,4 +311,43 @@ test_expect_success PERL 'difftool --tool-help' '\n \techo \"$tool_help\" | stdin_contains tool\n '\n \n+test_expect_success PERL 'setup change in subdirectory' '\n+\tgit checkout master &&\n+\tmkdir sub &&\n+\techo master >sub/sub &&\n+\tgit add sub/sub &&\n+\tgit commit -m \"added sub/sub\" &&\n+\techo test >>file &&\n+\techo test >>sub/sub &&\n+\tgit add . &&\n+\tgit commit -m \"modified both\"\n+'\n+\n+test_expect_success PERL 'difftool -d' '\n+\tdiff=$(git difftool -d --extcmd ls branch) &&\n+\techo \"$diff\" | stdin_contains sub &&\n+\techo \"$diff\" | stdin_contains file\n+'\n+\n+test_expect_success PERL 'difftool --dir-diff' '\n+\tdiff=$(git difftool --dir-diff --extcmd ls branch) &&\n+\techo \"$diff\" | stdin_contains sub &&\n+\techo \"$diff\" | stdin_contains file\n+'\n+\n+test_expect_success PERL 'difftool --dir-diff ignores --prompt' '\n+\tdiff=$(git difftool --dir-diff --prompt --extcmd ls branch) &&\n+\techo \"$diff\" | stdin_contains sub &&\n+\techo \"$diff\" | stdin_contains file\n+'\n+\n+test_expect_success PERL 'difftool --dir-diff from subdirectory' '\n+\t(\n+\t\tcd sub &&\n+\t\tdiff=$(git difftool --dir-diff --extcmd ls branch) &&\n+\t\techo \"$diff\" | stdin_contains sub &&\n+\t\techo \"$diff\" | stdin_contains file\n+\t)\n+'\n+\n test_done\n-- \n1.7.10.rc1.40.g756bbcd\n"},{"id":"187474","messageId":"1332428541-24878-3-git-send-email-tim.henigan@gmail.com","threadId":"30026","inReplyTo":"1332428541-24878-1-git-send-email-tim.henigan@gmail.com","subject":"[PATCH 13/9 v5] difftool: add '--no-gui' as an option","fromName":"Tim Henigan","fromEmail":"tim.henigan@gmail.com","sentAt":"2012-03-22T15:02:21Z","receivedAt":"2012-03-22T15:02:21Z","isPatch":true,"sender":{"key":"tim.henigan@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42022?v=4"},"body":"This commit teaches difftool to handle the '--no-gui' option. This option\nnegates the existing '--gui' option. The last setting given on the command\nline wins.\n\nThis allows a user to configure \"[alias] mdt = difftool --gui\", but still\nhave the ability to override the setting without error:\n\n$ git mdt --no-gui\n\nSigned-off-by: Tim Henigan <tim.henigan@gmail.com>\n---\n\nThis patch is new to the series. It fixes a potential bug pointed out\nby Junio Hamano on the Git developers list [1].\n\n[1]: http://thread.gmane.org/gmane.comp.version-control.git/193601/focus=193633\n\n\n git-difftool.perl   |    7 ++++---\n t/t7800-difftool.sh |   13 +++++++++++++\n 2 files changed, 17 insertions(+), 3 deletions(-)\n\ndiff --git a/git-difftool.perl b/git-difftool.perl\nindex 9892d1e..d9be7d6 100755\n--- a/git-difftool.perl\n+++ b/git-difftool.perl\n@@ -29,7 +29,8 @@ sub usage\n \tmy $exitcode = shift;\n \tprint << 'USAGE';\n usage: git difftool [-t|--tool=<tool>] [--tool-help]\n-                    [-x|--extcmd=<cmd>] [-g|--gui]\n+                    [-x|--extcmd=<cmd>]\n+                    [-g|--gui] [--no-gui]\n                     [--prompt] [-y|--no-prompt]\n                     [-d|--dir-diff]\n                     ['git diff' options]\n@@ -132,7 +133,7 @@ sub setup_dir_diff\n # parse command-line options. all unrecognized options and arguments\n # are passed through to the 'git diff' command.\n my ($difftool_cmd, $dirdiff, $extcmd, $gui, $help, $prompt, $tool_help);\n-GetOptions('g|gui' => \\$gui,\n+GetOptions('g|gui!' => \\$gui,\n \t'd|dir-diff' => \\$dirdiff,\n \t'h' => \\$help,\n \t'prompt!' => \\$prompt,\n@@ -169,7 +170,7 @@ if (defined($extcmd)) {\n \t\tusage(1);\n \t}\n }\n-if (defined($gui)) {\n+if ($gui) {\n \tmy $guitool = \"\";\n \t$guitool = Git::config('diff.guitool');\n \tif (length($guitool) > 0) {\ndiff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh\nindex 5f3ad3f..bbe71e5 100755\n--- a/t/t7800-difftool.sh\n+++ b/t/t7800-difftool.sh\n@@ -94,6 +94,19 @@ test_expect_success PERL 'difftool honors --gui' '\n \trestore_test_defaults\n '\n \n+test_expect_success PERL 'difftool --gui last setting wins' '\n+\tgit config diff.guitool bogus-tool &&\n+\tgit difftool --no-prompt --gui --no-gui &&\n+\n+\tgit config merge.tool bogus-tool &&\n+\tgit config diff.tool bogus-tool &&\n+\tgit config diff.guitool test-tool &&\n+\tdiff=$(git difftool --no-prompt --no-gui --gui branch) &&\n+\ttest \"$diff\" = \"branch\" &&\n+\n+\trestore_test_defaults\n+'\n+\n test_expect_success PERL 'difftool --gui works without configured diff.guitool' '\n \tgit config diff.tool test-tool &&\n \n-- \n1.7.10.rc1.40.g756bbcd\n"}]}