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

Re: [PATCH/RFC] Make "git remote rm <remote>" remove file refs/remotes/<remote>/HEAD

From
Junio C Hamano <junio@pobox.com>
Date
Mar 8, 2008, 01:46 UTC
Message-ID
<7vlk4uyoln.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<1204923732-29141-1-git-send-email-tlikonen@iki.fi>
Junio C Hamano <gitster@pobox.com> writes:
Show 6 quoted lines
> I think "update-ref -d" should remove the ref without dereferencing
> anyway.  How about not doing your patch at all (you would need to manually
> remove the symref in "prune" codepath as well), and instead doing this?
>
> I do not know how this reacts when the tracked HEAD points at a ref that
> lexicographically sorts earlier, say branch "A".

And it turns out it does not react very well. You would want to do something like this on top of that one.

-- >8 -- "remote rm": first remove symbolic and then real refs

This teaches a new %(reftype) to for-each-ref that returns "symref", "packed", or "plain" (we never pack symrefs, so this is the complete enumeration), and updates "git remote rm" to first remove the symrefs and then the actual refs.

Signed-off-by: Junio C Hamano <junio@pobox.com>
---
 builtin-for-each-ref.c |   13 +++++++++++++
 git-remote.perl        |   14 ++++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index 07d9c57..50e9eed 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -31,6 +31,7 @@ struct ref_sort {
 
 struct refinfo {
 	char *refname;
+	int reftype;
 	unsigned char objectname[20];
 	struct atom_value *value;
 };
@@ -40,6 +41,7 @@ static struct {
 	cmp_type cmp_type;
 } valid_atom[] = {
 	{ "refname" },
+	{ "reftype" },
 	{ "objecttype" },
 	{ "objectsize", FIELD_ULONG },
 	{ "objectname" },
@@ -568,6 +570,16 @@ static void populate_value(struct refinfo *ref)
 			char *s = xmalloc(len + 4);
 			sprintf(s, "%s^{}", ref->refname);
 			v->s = s;
+		} else if (!strcmp(name, "reftype")) {
+			char *s = xmalloc(20);
+			/* We do not pack symrefs */
+			if (ref->reftype & REF_ISSYMREF)
+				strcpy(s, "symref");
+			else if (ref->reftype & REF_ISPACKED)
+				strcpy(s, "packed");
+			else
+				strcpy(s, "plain");
+			v->s = s;
 		}
 	}
 
@@ -658,6 +670,7 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f
 	 */
 	ref = xcalloc(1, sizeof(*ref));
 	ref->refname = xstrdup(refname);
+	ref->reftype = flag;
 	hashcpy(ref->objectname, sha1);
 
 	cnt = cb->grab_cnt;
diff --git a/git-remote.perl b/git-remote.perl
index b30ed73..c57e29d 100755
--- a/git-remote.perl
+++ b/git-remote.perl
@@ -341,9 +341,19 @@ sub rm_remote {
 	};
 
 	my @refs = $git->command('for-each-ref',
-		'--format=%(refname) %(objectname)', "refs/remotes/$name");
+				 '--format=%(refname) %(reftype) %(objectname)',
+				 "refs/remotes/$name");
+	my @nonsym = ();
 	for (@refs) {
-		my ($ref, $object) = split;
+		my ($ref, $type, $object) = split;
+		if ($type !~ /symref/) {
+			push @nonsym, $_;
+		} else {
+			$git->command(qw(update-ref -d), $ref, $object);
+		}
+	}
+	for (@nonsym) {
+		my ($ref, $type, $object) = split;
 		$git->command(qw(update-ref -d), $ref, $object);
 	}
 	return 0;
Previous: Junio C HamanoNext: Teemu Likonen
Message 9 of 10 in “error: refs/remotes/origin/HEAD points nowhere!”
  1. Teemu LikonenMar 5, 2008
  2. Junio C HamanoMar 5, 2008
  3. Teemu LikonenMar 6, 2008
  4. builtin remote rm: remove symbolic refs, tooJohannes Schindelin, Mar 8, 2008
  5. Junio C HamanoMar 9, 2008
  6. Make "git remote rm <remote>" remove file refs/remotes/<remote>/HEADTeemu Likonen, Mar 7, 2008
  7. Teemu LikonenMar 7, 2008
  8. Junio C HamanoMar 8, 2008
  9. Junio C HamanoMar 8, 2008
  10. Teemu LikonenMar 8, 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.