From: Teemu Likonen <tlikonen@iki.fi>
To: git@vger.kernel.org
Cc: Teemu Likonen <tlikonen@iki.fi>
Subject: [PATCH/RFC] Make "git remote rm <remote>" remove file refs/remotes/<remote>/HEAD
Date: Fri, 7 Mar 2008 23:02:12 +0200 [thread overview]
Message-ID: <1204923732-29141-1-git-send-email-tlikonen@iki.fi> (raw)
In-Reply-To: <200803051338.44938.tlikonen@iki.fi>
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?
git-remote.perl | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/git-remote.perl b/git-remote.perl
index b30ed73..f1f2a1a 100755
--- a/git-remote.perl
+++ b/git-remote.perl
@@ -323,6 +323,7 @@ sub update_remote {
sub rm_remote {
my ($name) = @_;
+ my $git_dir = $ENV{GIT_DIR} || ".git";
if (!exists $remote->{$name}) {
print STDERR "No such remote $name\n";
return 1;
@@ -340,6 +341,11 @@ sub rm_remote {
}
};
+ my $remotes_dir = "$git_dir/refs/remotes/$name";
+ if (-f "$remotes_dir/HEAD") {
+ unlink "$remotes_dir/HEAD";
+ }
+
my @refs = $git->command('for-each-ref',
'--format=%(refname) %(objectname)', "refs/remotes/$name");
for (@refs) {
--
1.5.4.3.451.ga9908.dirty
next prev parent reply other threads:[~2008-03-07 21:02 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 ` Teemu Likonen [this message]
2008-03-07 22:18 ` [PATCH/RFC] Make "git remote rm <remote>" remove file refs/remotes/<remote>/HEAD Teemu Likonen
2008-03-08 1:45 ` Junio C Hamano
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=1204923732-29141-1-git-send-email-tlikonen@iki.fi \
--to=tlikonen@iki.fi \
--cc=git@vger.kernel.org \
/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).