[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]

 



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?

 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

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