reset: pass real rev name to add--interactive

The add--interactive --patch mode adjusts the UI based on whether we are pulling changes from HEAD or elsewhere (in the former case it asks to unstage the reverse hunk, rather than apply the forward hunk). Commit 166ec2e taught reset to work on an unborn branch, but in doing so, switched to always providing add--interactive with the sha1 rather than the symbolic name. This meant we always used the "apply" interface, even for "git reset -p HEAD". We can fix this by passing the symbolic name to add--interactive. Since it understands unborn branches these days, we do not even have to cover this special case ourselves; we can simply pass HEAD. The tests in t7105 now check that the right interface is used in each circumstance (and notice the regression from 166ec2e we are fixing). The test in t7106 checks that we get this right for the unborn case, too (not a regression, since it didn't work at all before, but a nice improvement). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 25, 2013 at 02:54 UTC b3e9ce13320f62e07fcb88a5cdf3c0462c195e95
3 files changed +10 -7
builtin/reset.c
+1 -1
@@ -304,7 +304,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
304 if (patch_mode) {
305 if (reset_type != NONE)
306 die(_("--patch is incompatible with --{hard,mixed,soft}"));
307 - return run_add_interactive(sha1_to_hex(sha1), "--patch=reset", &pathspec);
307 + return run_add_interactive(rev, "--patch=reset", &pathspec);
308 }
309
310 /* git reset tree [--] paths... can be used to
t/t7105-reset-patch.sh
+6 -4
@@ -25,15 +25,17 @@ test_expect_success PERL 'saying "n" does nothing' '
25 '
26
27 test_expect_success PERL 'git reset -p' '
28 - (echo n; echo y) | git reset -p &&
28 + (echo n; echo y) | git reset -p >output &&
29 verify_state dir/foo work head &&
30 - verify_saved_state bar
30 + verify_saved_state bar &&
31 + test_i18ngrep "Unstage" output
32 '
33
34 test_expect_success PERL 'git reset -p HEAD^' '
34 - (echo n; echo y) | git reset -p HEAD^ &&
35 + (echo n; echo y) | git reset -p HEAD^ >output &&
36 verify_state dir/foo work parent &&
36 - verify_saved_state bar
37 + verify_saved_state bar &&
38 + test_i18ngrep "Apply" output
39 '
40
41 # The idea in the rest is that bar sorts first, so we always say 'y'
t/t7106-reset-unborn-branch.sh
+3 -2
@@ -37,11 +37,12 @@ test_expect_success PERL 'reset -p' '
37 rm .git/index &&
38 git add a &&
39 echo y >yes &&
40 - git reset -p <yes &&
40 + git reset -p <yes >output &&
41
42 >expect &&
43 git ls-files >actual &&
44 - test_cmp expect actual
44 + test_cmp expect actual &&
45 + test_i18ngrep "Unstage" output
46 '
47
48 test_expect_success 'reset --soft is a no-op' '