git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] builtin-reflog: fix deletion of HEAD entries

From
PBPieter de Bie <pdebie@ai.rug.nl>
Date
Aug 9, 2008, 23:33 UTC
Message-ID
<1218324810-35376-2-git-send-email-pdebie@ai.rug.nl>
In-Reply-To
<1218324810-35376-1-git-send-email-pdebie@ai.rug.nl>

dwim_ref() used to resolve HEAD to its symlink (like refs/heads/master), making a call to 'git reflog delete HEAD@{1}' to actually delete the second entry in the master reflog.

This patch makes a special case for HEAD (as that's the only non-branch reflog we keep), fixing the issue.

Signed-off-by: Pieter de Bie <pdebie@ai.rug.nl>
---
 builtin-reflog.c  |   15 ++++++++++++---
 t/t1410-reflog.sh |    2 +-
 2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/builtin-reflog.c b/builtin-reflog.c
index 0c34e37..5af3f28 100644
--- a/builtin-reflog.c
+++ b/builtin-reflog.c
@@ -604,9 +604,18 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
 			continue;
 		}
 
-		if (!dwim_ref(argv[i], spec - argv[i], sha1, &ref)) {
-			status |= error("%s points nowhere!", argv[i]);
-			continue;
+		if (!strncmp(argv[i], "HEAD", 4)) {
+			ref = xstrdup("HEAD");
+			if (!resolve_ref(ref, sha1, 1, NULL)) {
+				status |= error("%s points nowhere!", argv[i]);
+				continue;
+			}
+		}
+		else {
+			if (!dwim_ref(argv[i], spec - argv[i], sha1, &ref)) {
+				status |= error("%s points nowhere!", argv[i]);
+				continue;
+			}
 		}
 
 		recno = strtoul(spec + 2, &ep, 10);
diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh
index 3b9860e..5b24f05 100755
--- a/t/t1410-reflog.sh
+++ b/t/t1410-reflog.sh
@@ -175,7 +175,7 @@ test_expect_success 'recover and check' '
 
 '
 
-test_expect_failure 'delete' '
+test_expect_success 'delete' '
 	echo 1 > C &&
 	test_tick &&
 	git commit -m rat C &&
-- 
1.6.0.rc0.320.g49281
Previous: Pieter de BieNext: Junio C Hamano
Message 2 of 9 in “reflog test: add more tests for 'reflog delete'”
  1. 1/2 reflog test: add more tests for 'reflog delete'Pieter de Bie, Aug 9, 2008
  2. 2/2 builtin-reflog: fix deletion of HEAD entriesPieter de Bie, Aug 9, 2008
  3. Junio C HamanoAug 10, 2008
  4. Junio C HamanoAug 10, 2008
  5. Pieter de BieAug 10, 2008
  6. Johannes SixtAug 10, 2008
  7. Junio C HamanoAug 10, 2008
  8. Pieter de BieAug 10, 2008
  9. builtin-reflog: Allow reflog expire to name partial refPieter de Bie, Aug 10, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.