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

[PATCH 5/5] branch: show targets of deleted symrefs, not sha1s

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Oct 18, 2012, 12:08 UTC
Message-ID
<507FF123.2030709@lsrfire.ath.cx>
In-Reply-To
<507FEF0B.1060309@lsrfire.ath.cx>

git branch reports the abbreviated hash of the head commit of a deleted branch to make it easier for a user to undo the operation. For symref branches this doesn't help. Print the symref target instead for them.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 builtin/branch.c  | 19 +++++++++++--------
 t/t3200-branch.sh |  5 ++---
 2 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index d87035a..1ec9c02 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -251,15 +251,18 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
 			      : _("Error deleting branch '%s'"),
 			      bname.buf);
 			ret = 1;
-		} else {
-			if (!quiet)
-				printf(remote_branch
-				       ? _("Deleted remote branch %s (was %s).\n")
-				       : _("Deleted branch %s (was %s).\n"),
-				       bname.buf,
-				       find_unique_abbrev(sha1, DEFAULT_ABBREV));
-			delete_branch_config(bname.buf);
+			continue;
+		}
+		if (!quiet) {
+			printf(remote_branch
+			       ? _("Deleted remote branch %s (was %s).\n")
+			       : _("Deleted branch %s (was %s).\n"),
+			       bname.buf,
+			       (flags & REF_ISSYMREF)
+			       ? target
+			       : find_unique_abbrev(sha1, DEFAULT_ABBREV));
 		}
+		delete_branch_config(bname.buf);
 	}
 
 	free(name);
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 1323f6f..80e6be3 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -265,8 +265,7 @@ test_expect_success 'config information was renamed, too' \
 test_expect_success 'deleting a symref' '
 	git branch target &&
 	git symbolic-ref refs/heads/symref refs/heads/target &&
-	sha1=$(git rev-parse symref | cut -c 1-7) &&
-	echo "Deleted branch symref (was $sha1)." >expect &&
+	echo "Deleted branch symref (was refs/heads/target)." >expect &&
 	git branch -d symref >actual &&
 	test_path_is_file .git/refs/heads/target &&
 	test_path_is_missing .git/refs/heads/symref &&
@@ -276,7 +275,7 @@ test_expect_success 'deleting a symref' '
 test_expect_success 'deleting a dangling symref' '
 	git symbolic-ref refs/heads/dangling-symref nowhere &&
 	test_path_is_file .git/refs/heads/dangling-symref &&
-	echo "Deleted branch dangling-symref (was 0000000)." >expect &&
+	echo "Deleted branch dangling-symref (was nowhere)." >expect &&
 	git branch -d dangling-symref >actual &&
 	test_path_is_missing .git/refs/heads/dangling-symref &&
 	test_i18ncmp expect actual
-- 
1.7.12
Previous: Junio C Hamano
Message 16 of 16 in “BUG when trying to delete symbolic refs”
  1. Johan HerlandOct 15, 2012
  2. René ScharfeOct 16, 2012
  3. refs: lock symref that is to be deleted, not its targetRené Scharfe, Oct 16, 2012
  4. Junio C HamanoOct 16, 2012
  5. René ScharfeOct 18, 2012
  6. 1/5 branch: factor out check_branch_commit()René Scharfe, Oct 18, 2012
  7. 2/5 branch: factor out delete_branch_config()René Scharfe, Oct 18, 2012
  8. 3/5 branch: delete symref branch, not its targetRené Scharfe, Oct 18, 2012
  9. 4/5 branch: skip commit checks when deleting symref branchesRené Scharfe, Oct 18, 2012
  10. Junio C HamanoOct 18, 2012
  11. 0/2 Fix remaining issue when deleting symrefsJohan Herland, Oct 21, 2012
  12. 1/2 t1400-update-ref: Add test verifying bug with symrefs in delete_ref()Johan Herland, Oct 21, 2012
  13. 2/2 Fix failure to delete a packed ref through a symrefJohan Herland, Oct 21, 2012
  14. René ScharfeOct 21, 2012
  15. Junio C HamanoOct 21, 2012
  16. 5/5 branch: show targets of deleted symrefs, not sha1sRené Scharfe, Oct 18, 2012

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.