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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Teemu Likonen <tlikonen@xxxxxx> 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@xxxxxx>
> ---
>
> 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@xxxxxxxxx>
---
 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)) {
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux