Skip to content

Commit b3e9ce1

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 954312a commit b3e9ce1

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

builtin/reset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
304304
if (patch_mode) {
305305
if (reset_type != NONE)
306306
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);
308308
}
309309

310310
/* git reset tree [--] paths... can be used to

t/t7105-reset-patch.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ test_expect_success PERL 'saying "n" does nothing' '
2525
'
2626

2727
test_expect_success PERL 'git reset -p' '
28-
(echo n; echo y) | git reset -p &&
28+
(echo n; echo y) | git reset -p >output &&
2929
verify_state dir/foo work head &&
30-
verify_saved_state bar
30+
verify_saved_state bar &&
31+
test_i18ngrep "Unstage" output
3132
'
3233

3334
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 &&
3536
verify_state dir/foo work parent &&
36-
verify_saved_state bar
37+
verify_saved_state bar &&
38+
test_i18ngrep "Apply" output
3739
'
3840

3941
# The idea in the rest is that bar sorts first, so we always say 'y'

t/t7106-reset-unborn-branch.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ test_expect_success PERL 'reset -p' '
3737
rm .git/index &&
3838
git add a &&
3939
echo y >yes &&
40-
git reset -p <yes &&
40+
git reset -p <yes >output &&
4141
4242
>expect &&
4343
git ls-files >actual &&
44-
test_cmp expect actual
44+
test_cmp expect actual &&
45+
test_i18ngrep "Unstage" output
4546
'
4647

4748
test_expect_success 'reset --soft is a no-op' '

0 commit comments

Comments
 (0)