{"thread":{"id":"45262","subject":"[PATCH] add--interactive: fix missing file prompt for patch mode with \"-i\"","startedAt":"2017-03-02T10:16:03Z","lastAt":"2017-03-02T10:16:03Z","messageCount":1,"participants":["Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"313057","messageId":"20170302094822.7a65bk2i3qciw6jg@sigill.intra.peff.net","threadId":"45262","inReplyTo":null,"subject":"[PATCH] add--interactive: fix missing file prompt for patch mode with \"-i\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-03-02T09:48:22Z","receivedAt":"2017-03-02T10:16:03Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"When invoked as \"git add -i\", each menu interactive menu\noption prompts the user to select a list of files. This\nincludes the \"patch\" option, which gets the list before\nstarting the hunk-selection loop.\n\nAs \"git add -p\", it behaves differently, and jumps straight\nto the hunk selection loop.\n\nSince 0539d5e6d (i18n: add--interactive: mark patch prompt\nfor translation, 2016-12-14), the \"add -i\" case mistakenly\njumps to straight to the hunk-selection loop. Prior to that\ncommit the distinction between the two cases was managed by\nthe $patch_mode variable. That commit used $patch_mode for\nsomething else, and moved the old meaning to the \"$cmd\"\nvariable.  But it forgot to update the $patch_mode check\ninside patch_update_cmd() which controls the file-list\nbehavior.\n\nThe simplest fix would be to change that line to check $cmd.\nBut while we're here, let's use a less obscure name for this\nflag: $patch_mode_only, a boolean which tells whether we are\nin full-interactive mode or only in patch-mode.\n\nReported-by: Henrik Grubbström <grubba@grubba.org>\nSigned-off-by: Jeff King <peff@peff.net>\n---\n git-add--interactive.perl  |  8 ++++----\n t/t3701-add-interactive.sh | 18 ++++++++++++++++++\n 2 files changed, 22 insertions(+), 4 deletions(-)\n\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex 982593c89..f5c816e27 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -92,7 +92,7 @@ sub colored {\n }\n \n # command line options\n-my $cmd;\n+my $patch_mode_only;\n my $patch_mode;\n my $patch_mode_revision;\n \n@@ -1299,7 +1299,7 @@ sub patch_update_cmd {\n \t\t}\n \t\treturn 0;\n \t}\n-\tif ($patch_mode) {\n+\tif ($patch_mode_only) {\n \t\t@them = @mods;\n \t}\n \telse {\n@@ -1721,7 +1721,7 @@ sub process_args {\n \t\tdie sprintf(__(\"invalid argument %s, expecting --\"),\n \t\t\t       $arg) unless $arg eq \"--\";\n \t\t%patch_mode_flavour = %{$patch_modes{$patch_mode}};\n-\t\t$cmd = 1;\n+\t\t$patch_mode_only = 1;\n \t}\n \telsif ($arg ne \"--\") {\n \t\tdie sprintf(__(\"invalid argument %s, expecting --\"), $arg);\n@@ -1758,7 +1758,7 @@ sub main_loop {\n \n process_args();\n refresh();\n-if ($cmd) {\n+if ($patch_mode_only) {\n \tpatch_update_cmd();\n }\n else {\ndiff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh\nindex 5ffe78e92..aaa258daa 100755\n--- a/t/t3701-add-interactive.sh\n+++ b/t/t3701-add-interactive.sh\n@@ -394,4 +394,22 @@ test_expect_success 'diffs can be colorized' '\n \tgrep \"$(printf \"\\\\033\")\" output\n '\n \n+test_expect_success 'patch-mode via -i prompts for files' '\n+\tgit reset --hard &&\n+\n+\techo one >file &&\n+\techo two >test &&\n+\tgit add -i <<-\\EOF &&\n+\tpatch\n+\ttest\n+\n+\ty\n+\tquit\n+\tEOF\n+\n+\techo test >expect &&\n+\tgit diff --cached --name-only >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.12.0.367.gb23790f66\n"}]}