Please, one patch per message in the future.
My vague unhappiness at "git reset" may have come from this.
Wouldn't it make sense to make "git reset" basically a synonym for
"git rm --cached" when in the 'branch yet to be born' case?
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
diff --git a/builtin/reset.c b/builtin/reset.c
index 0037be4..cde103f 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -236,6 +236,7 @@ static void die_if_unmerged_cache(int reset_type)
int cmd_reset(int argc, const char **argv, const char *prefix)
{
int i = 0, reset_type = NONE, update_ref_status = 0, quiet = 0;
+ int unborn_branch = 0;
int patch_mode = 0;
const char *rev = "HEAD";
unsigned char sha1[20], *orig = NULL, sha1_orig[20],
@@ -299,13 +300,27 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
}
}
- if (get_sha1(rev, sha1))
+ if (!strcmp(rev, "HEAD")) {
+ /* We may be on a branch yet to be born. */
+ resolve_ref("HEAD", sha1, 0, NULL);
+ if (is_null_sha1(sha1)) {
+ unborn_branch = 1;
+ commit = NULL;
+ hashcpy(sha1, (const unsigned char *) EMPTY_TREE_SHA1_BIN);
+
+ /* Only accept "git reset -- <paths>" form, for now. */
+ if (i == argc || patch_mode)
+ die("Failed to resolve 'HEAD' as a valid ref.");
+ }
+ } else if (get_sha1(rev, sha1))
die("Failed to resolve '%s' as a valid ref.", rev);
- commit = lookup_commit_reference(sha1);
- if (!commit)
- die("Could not parse object '%s'.", rev);
- hashcpy(sha1, commit->object.sha1);
+ if (!unborn_branch) {
+ commit = lookup_commit_reference(sha1);
+ if (!commit)
+ die("Could not parse object '%s'.", rev);
+ hashcpy(sha1, commit->object.sha1);
+ }
if (patch_mode) {
if (reset_type != NONE)
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html