git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Teemu Likonen <tlikonen@iki.fi>
Cc: git@vger.kernel.org
Subject: Re: [PATCH/RFC] Make "git remote rm <remote>" remove file refs/remotes/<remote>/HEAD
Date: Fri, 07 Mar 2008 17:45:46 -0800	[thread overview]
Message-ID: <7vskz2yomt.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 1204923732-29141-1-git-send-email-tlikonen@iki.fi

Teemu Likonen <tlikonen@iki.fi> writes:

> The command "git remote rm <remote>" used to leave the
> refs/remotes/<remote>/HEAD file lying in the directory. This usually
> happens when user has cloned a remote repository and later decided to
> remove the default "origin" with "git remote rm origin". The result is
> that several git commans display the error message
>
>   error: refs/remotes/origin/HEAD points nowhere!
>
> This patch makes "git remote rm" remove the HEAD file if it exists.
>
> Signed-off-by: Teemu Likonen <tlikonen@iki.fi>
> ---
>
> I have never written or even read any perl code before this (I'm not really
> a programmer) but I managed to come up with this. This seems to work well. If
> more error checking or something is needed, I guess somebody else has to do it;
> my skills aren't quite enough. :)
>
> Any comments?

Hmm.  The loop grabs everything under refs/remotes/$that_remote/ and runs
"update-ref -d" on them.

I somehow had an impression that --no-deref option to update-ref was
invented to allow operating on the symbolic ref itself, instead of
operating on the ref it points at, but it does not seem to work.

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".

-- >8 --
delete_ref(): when symref is given, delete it, not the underlying ref.

Removing the underlying ref without touching the symref does not make any
sense.  An alternative would be to remove the symref _and_ the underlying
ref, but this should do for now.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 refs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/refs.c b/refs.c
index c979fb1..e7c0c38 100644
--- a/refs.c
+++ b/refs.c
@@ -887,7 +887,7 @@ int delete_ref(const char *refname, const unsigned char *sha1)
 	struct ref_lock *lock;
 	int err, i, ret = 0, flag = 0;
 
-	lock = lock_ref_sha1_basic(refname, sha1, 0, &flag);
+	lock = lock_ref_sha1_basic(refname, sha1, REF_NODEREF, &flag);
 	if (!lock)
 		return 1;
 	if (!(flag & REF_ISPACKED)) {

  parent reply	other threads:[~2008-03-08  1:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-05 11:38 error: refs/remotes/origin/HEAD points nowhere! Teemu Likonen
2008-03-05 21:24 ` Junio C Hamano
2008-03-06  7:50   ` Teemu Likonen
2008-03-08 22:40   ` [PATCH] builtin remote rm: remove symbolic refs, too Johannes Schindelin
2008-03-09 10:24     ` Junio C Hamano
2008-03-07 21:02 ` [PATCH/RFC] Make "git remote rm <remote>" remove file refs/remotes/<remote>/HEAD Teemu Likonen
2008-03-07 22:18   ` Teemu Likonen
2008-03-08  1:45   ` Junio C Hamano [this message]
2008-03-08  1:46   ` Junio C Hamano
2008-03-08  6:16     ` Teemu Likonen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vskz2yomt.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=tlikonen@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).