Skip to content

Commit 13243c2

Browse files
committed
reset: the command takes committish
This is not strictly correct, in that resetting selected index entries from corresponding paths out of a given tree without moving HEAD is a valid operation, and in such case a tree-ish would suffice. But the existing code already requires a committish in the codepath, so let's be consistent with it for now. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 75f5ac0 commit 13243c2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

builtin/reset.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
276276
* Otherwise, argv[i] could be either <rev> or <paths> and
277277
* has to be unambiguous.
278278
*/
279-
else if (!get_sha1(argv[i], sha1)) {
279+
else if (!get_sha1_committish(argv[i], sha1)) {
280280
/*
281281
* Ok, argv[i] looks like a rev; it should not
282282
* be a filename.
@@ -289,9 +289,15 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
289289
}
290290
}
291291

292-
if (get_sha1(rev, sha1))
292+
if (get_sha1_committish(rev, sha1))
293293
die(_("Failed to resolve '%s' as a valid ref."), rev);
294294

295+
/*
296+
* NOTE: As "git reset $treeish -- $path" should be usable on
297+
* any tree-ish, this is not strictly correct. We are not
298+
* moving the HEAD to any commit; we are merely resetting the
299+
* entries in the index to that of a treeish.
300+
*/
295301
commit = lookup_commit_reference(sha1);
296302
if (!commit)
297303
die(_("Could not parse object '%s'."), rev);

t/t1512-rev-parse-disambiguation.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ test_expect_success 'git log takes only commit-ish' '
121121
git log 000000000
122122
'
123123

124-
test_expect_failure 'git reset takes only commit-ish' '
124+
test_expect_success 'git reset takes only commit-ish' '
125125
git reset 000000000
126126
'
127127

0 commit comments

Comments
 (0)