[PATCH/RFC] Make "git remote rm <remote>" remove file refs/remotes/<remote>/HEAD
- From
- Teemu Likonen <tlikonen@iki.fi>
- Date
- Mar 7, 2008, 21:02 UTC
- Message-ID
- <1204923732-29141-1-git-send-email-tlikonen@iki.fi>
- 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