Skip to content

Commit 34dc348

Browse files
committed
Merge branch 'nl/reset-patch-takes-a-tree' into next
"git reset --patch $object" without any pathspec should allow a tree object to be given, but incorrectly required a committish, which has been corrected. * nl/reset-patch-takes-a-tree: reset: parse rev as tree-ish in patch mode
2 parents fa83339 + 0a8e303 commit 34dc348

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

builtin/reset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
320320
if (unborn) {
321321
/* reset on unborn branch: treat as reset to empty tree */
322322
oidcpy(&oid, the_hash_algo->empty_tree);
323-
} else if (!pathspec.nr) {
323+
} else if (!pathspec.nr && !patch_mode) {
324324
struct commit *commit;
325325
if (get_oid_committish(rev, &oid))
326326
die(_("Failed to resolve '%s' as a valid revision."), rev);

t/t7105-reset-patch.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,27 @@ test_expect_success PERL 'git reset -p HEAD^' '
3838
test_i18ngrep "Apply" output
3939
'
4040

41+
test_expect_success PERL 'git reset -p HEAD^^{tree}' '
42+
test_write_lines n y | git reset -p HEAD^^{tree} >output &&
43+
verify_state dir/foo work parent &&
44+
verify_saved_state bar &&
45+
test_i18ngrep "Apply" output
46+
'
47+
48+
test_expect_success PERL 'git reset -p HEAD^:dir/foo (blob fails)' '
49+
set_and_save_state dir/foo work work &&
50+
test_must_fail git reset -p HEAD^:dir/foo &&
51+
verify_saved_state dir/foo &&
52+
verify_saved_state bar
53+
'
54+
55+
test_expect_success PERL 'git reset -p aaaaaaaa (unknown fails)' '
56+
set_and_save_state dir/foo work work &&
57+
test_must_fail git reset -p aaaaaaaa &&
58+
verify_saved_state dir/foo &&
59+
verify_saved_state bar
60+
'
61+
4162
# The idea in the rest is that bar sorts first, so we always say 'y'
4263
# first and if the path limiter fails it'll apply to bar instead of
4364
# dir/foo. There's always an extra 'n' to reject edits to dir/foo in

0 commit comments

Comments
 (0)