Skip to content

Commit

Permalink
reset: pass real rev name to add--interactive
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Oct 25, 2013
1 parent 954312a commit b3e9ce1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion builtin/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
if (patch_mode) {
if (reset_type != NONE)
die(_("--patch is incompatible with --{hard,mixed,soft}"));
return run_add_interactive(sha1_to_hex(sha1), "--patch=reset", &pathspec);
return run_add_interactive(rev, "--patch=reset", &pathspec);
}

/* git reset tree [--] paths... can be used to
Expand Down
10 changes: 6 additions & 4 deletions t/t7105-reset-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ test_expect_success PERL 'saying "n" does nothing' '
'

test_expect_success PERL 'git reset -p' '
(echo n; echo y) | git reset -p &&
(echo n; echo y) | git reset -p >output &&
verify_state dir/foo work head &&
verify_saved_state bar
verify_saved_state bar &&
test_i18ngrep "Unstage" output
'

test_expect_success PERL 'git reset -p HEAD^' '
(echo n; echo y) | git reset -p HEAD^ &&
(echo n; echo y) | git reset -p HEAD^ >output &&
verify_state dir/foo work parent &&
verify_saved_state bar
verify_saved_state bar &&
test_i18ngrep "Apply" output
'

# The idea in the rest is that bar sorts first, so we always say 'y'
Expand Down
5 changes: 3 additions & 2 deletions t/t7106-reset-unborn-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ test_expect_success PERL 'reset -p' '
rm .git/index &&
git add a &&
echo y >yes &&
git reset -p <yes &&
git reset -p <yes >output &&
>expect &&
git ls-files >actual &&
test_cmp expect actual
test_cmp expect actual &&
test_i18ngrep "Unstage" output
'

test_expect_success 'reset --soft is a no-op' '
Expand Down

0 comments on commit b3e9ce1

Please sign in to comment.