[PATCH v5 23/25] reset: the command takes committish

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 builtin/reset.c                     | 10 ++++++++--
 t/t1512-rev-parse-disambiguation.sh |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/builtin/reset.c b/builtin/reset.c
index 8c2c1d5..392fb63 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -276,7 +276,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 		 * Otherwise, argv[i] could be either <rev> or <paths> and
 		 * has to be unambiguous.
 		 */
-		else if (!get_sha1(argv[i], sha1)) {
+		else if (!get_sha1_committish(argv[i], sha1)) {
 			/*
 			 * Ok, argv[i] looks like a rev; it should not
 			 * be a filename.
@@ -289,9 +289,15 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 		}
 	}
 
-	if (get_sha1(rev, sha1))
+	if (get_sha1_committish(rev, sha1))
 		die(_("Failed to resolve '%s' as a valid ref."), rev);
 
+	/*
+	 * NOTE: As "git reset $treeish -- $path" should be usable on
+	 * any tree-ish, this is not strictly correct. We are not
+	 * moving the HEAD to any commit; we are merely resetting the
+	 * entries in the index to that of a treeish.
+	 */
 	commit = lookup_commit_reference(sha1);
 	if (!commit)
 		die(_("Could not parse object '%s'."), rev);
diff --git a/t/t1512-rev-parse-disambiguation.sh b/t/t1512-rev-parse-disambiguation.sh
index dd42729..c3b78b9 100755
--- a/t/t1512-rev-parse-disambiguation.sh
+++ b/t/t1512-rev-parse-disambiguation.sh
@@ -121,7 +121,7 @@ test_expect_success 'git log takes only commit-ish' '
 	git log 11021982
 '
 
-test_expect_failure 'git reset takes only commit-ish' '
+test_expect_success 'git reset takes only commit-ish' '
 	git reset 11021982
 '
 
-- 
1.7.11.1.229.g706c98f

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]