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 <gitster@pobox.com>
Junio C Hamano committed
Jul 3, 2012 at 10:04 UTC
13243c2c7a758bb6510ba26d0372f384b5f422ce
2 files changed
+9
-3
builtin/reset.c
+8
-2
@@ -276,7 +276,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
276
* Otherwise, argv[i] could be either <rev> or <paths> and
277
* has to be unambiguous.
278
*/
279
- else if (!get_sha1(argv[i], sha1)) {
279
+ else if (!get_sha1_committish(argv[i], sha1)) {
280
/*
281
* Ok, argv[i] looks like a rev; it should not
282
* be a filename.
@@ -289,9 +289,15 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
289
}
290
}
291
292
- if (get_sha1(rev, sha1))
292
+ if (get_sha1_committish(rev, sha1))
293
die(_("Failed to resolve '%s' as a valid ref."), rev);
294
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
+ */
301
commit = lookup_commit_reference(sha1);
302
if (!commit)
303
die(_("Could not parse object '%s'."), rev);
t/t1512-rev-parse-disambiguation.sh
+1
-1
@@ -121,7 +121,7 @@ test_expect_success 'git log takes only commit-ish' '
121
git log 000000000
122
'
123
124
-test_expect_failure 'git reset takes only commit-ish' '
124
+test_expect_success 'git reset takes only commit-ish' '
125
git reset 000000000
126
'
127