{"thread":{"id":"8457","subject":"[PATCH] remote: add 'rm' subcommand","startedAt":"2007-06-05T23:25:23Z","lastAt":"2007-09-03T10:07:51Z","messageCount":7,"participants":["James Bowes","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"44110","messageId":"11810859232541-git-send-email-jbowes@dangerouslyinc.com","threadId":"8457","inReplyTo":null,"subject":"[PATCH] remote: add 'rm' subcommand","fromName":"James Bowes","fromEmail":"jbowes@dangerouslyinc.com","sentAt":"2007-06-05T23:25:23Z","receivedAt":"2007-06-05T23:25:23Z","isPatch":true,"sender":{"key":"jbowes@dangerouslyinc.com","avatar":"https://gravatar.com/avatar/a2fe98c66b2b47a9fa9d2ba92ff949d54c3208b1f8acc2e745b4b84ae3c4483a?d=mp&s=160"},"body":"Introduce git-remote rm <name> which will:\n - Remove the remote config entry for <name>.\n - Remove any config entries for tracking branches of <name>.\n - Remove any stored remote branches of <name>.\n\nSigned-off-by: James Bowes <jbowes@dangerouslyinc.com>\n---\n\nHere's a quick patch to implement the reverse of 'git-remote add', as\nwas asked about recently on the list[1]. Tested minimally with a\ncollection of on-disk repositories.\n\nIf there is any interest in this, I'll follow up later with additions\nto the docs.\n\n-James\n\n[1] http://article.gmane.org/gmane.comp.version-control.git/49222\n\n git-remote.perl |   38 ++++++++++++++++++++++++++++++++++++++\n 1 files changed, 38 insertions(+), 0 deletions(-)\n\ndiff --git a/git-remote.perl b/git-remote.perl\nindex 5763799..05aa8d6 100755\n--- a/git-remote.perl\n+++ b/git-remote.perl\n@@ -313,6 +313,34 @@ sub update_remote {\n \t}\n }\n \n+sub rm_remote {\n+    my ($name) = @_;\n+\tif (!exists $remote->{$name}) {\n+\t\tprint STDERR \"No such remote $name\\n\";\n+\t\treturn;\n+\t}\n+\n+\t$git->command('config', '--remove-section', \"remote.$name\");\n+\n+\teval {\n+\t    my @trackers = $git->command('config', '--get-regexp',\n+\t\t\t'branch.*.remote', $name);\n+\t\tfor (@trackers) {\n+\t\t\t/^branch\\.(.*)?\\.remote/;\n+\t\t\t$git->config('--unset', \"branch.$1.remote\");\n+\t\t\t$git->config('--unset', \"branch.$1.merge\");\n+\t\t}\n+\t};\n+\n+\n+    my @refs = $git->command('for-each-ref',\n+\t\t'--format=%(refname) %(objectname)', \"refs/remotes/$name\");\n+\tfor (@refs) {\n+\t\t($ref, $object) = split;\n+\t\t$git->command(qw(update-ref -d), $ref, $object);\n+\t}\n+}\n+\n sub add_usage {\n \tprint STDERR \"Usage: git remote add [-f] [-t track]* [-m master] <name> <url>\\n\";\n \texit(1);\n@@ -403,9 +431,19 @@ elsif ($ARGV[0] eq 'add') {\n \t}\n \tadd_remote($ARGV[1], $ARGV[2], \\%opts);\n }\n+elsif ($ARGV[0] eq 'rm') {\n+\tif (@ARGV <= 1) {\n+\t\tprint STDERR \"Usage: git remote rm <remote>\\n\";\n+\t}\n+    else {\n+        rm_remote($ARGV[1]);\n+\t}\n+    exit(1);\n+}\n else {\n \tprint STDERR \"Usage: git remote\\n\";\n \tprint STDERR \"       git remote add <name> <url>\\n\";\n+\tprint STDERR \"       git remote rm <name>\\n\";\n \tprint STDERR \"       git remote show <name>\\n\";\n \tprint STDERR \"       git remote prune <name>\\n\";\n \tprint STDERR \"       git remote update [group]\\n\";\n-- \n1.5.2.1.851.g432c\n"},{"id":"46573","messageId":"Pine.LNX.4.64.0707052338150.9789@racer.site","threadId":"8457","inReplyTo":"11810859232541-git-send-email-jbowes@dangerouslyinc.com","subject":"Re: [PATCH] remote: add 'rm' subcommand","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-05T22:38:41Z","receivedAt":"2007-07-05T22:38:41Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 5 Jun 2007, James Bowes wrote:\n\n> Introduce git-remote rm <name> which will:\n>  - Remove the remote config entry for <name>.\n>  - Remove any config entries for tracking branches of <name>.\n>  - Remove any stored remote branches of <name>.\n\nAny word on this?\n\nCiao,\nDscho\n"},{"id":"46689","messageId":"20070707152242.GC19782@crux.rdu.redhat.com","threadId":"8457","inReplyTo":"Pine.LNX.4.64.0707052338150.9789@racer.site","subject":"[PATCH] remote: document the 'rm' subcommand","fromName":"James Bowes","fromEmail":"jbowes@dangerouslyinc.com","sentAt":"2007-07-07T15:22:43Z","receivedAt":"2007-07-07T15:22:43Z","isPatch":true,"sender":{"key":"jbowes@dangerouslyinc.com","avatar":"https://gravatar.com/avatar/a2fe98c66b2b47a9fa9d2ba92ff949d54c3208b1f8acc2e745b4b84ae3c4483a?d=mp&s=160"},"body":"Signed-off-by: James Bowes <jbowes@dangerouslyinc.com>\n---\n\nSo I still think 'git remote rm' would be nice to have. Here's a bit of\ndocumentation for it.\n\n Documentation/git-remote.txt |    6 ++++++\n 1 files changed, 6 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt\nindex 61a6022..fff40ca 100644\n--- a/Documentation/git-remote.txt\n+++ b/Documentation/git-remote.txt\n@@ -11,6 +11,7 @@ SYNOPSIS\n [verse]\n 'git-remote'\n 'git-remote' add [-t <branch>] [-m <branch>] [-f] <name> <url>\n+'git-remote' rm <name>\n 'git-remote' show <name>\n 'git-remote' prune <name>\n 'git-remote' update [group]\n@@ -46,6 +47,11 @@ With `-m <master>` option, `$GIT_DIR/remotes/<name>/HEAD` is set\n up to point at remote's `<master>` branch instead of whatever\n branch the `HEAD` at the remote repository actually points at.\n \n+'rm'::\n+\n+Remove the remote named <name>. All remote tracking branches and\n+configuration settings for the remote are removed.\n+\n 'show'::\n \n Gives some information about the remote <name>.\n-- \n1.5.3.rc0.838.gdf39a-dirty\n"},{"id":"46692","messageId":"Pine.LNX.4.64.0707071720490.4093@racer.site","threadId":"8457","inReplyTo":"20070707152242.GC19782@crux.rdu.redhat.com","subject":"Re: [PATCH] remote: document the 'rm' subcommand","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-07T16:21:48Z","receivedAt":"2007-07-07T16:21:48Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 7 Jul 2007, James Bowes wrote:\n\n> Signed-off-by: James Bowes <jbowes@dangerouslyinc.com>\n> ---\n> \n> So I still think 'git remote rm' would be nice to have. Here's a bit of \n> documentation for it.\n\nMe, too. However, I would feel more comfortable with a test suite that it \nactually works as advertised. It is on my TODO list, which keeps growing \non top of it.\n\nCiao,\nDscho\n"},{"id":"46715","messageId":"7vodio6ivo.fsf@assigned-by-dhcp.cox.net","threadId":"8457","inReplyTo":"20070707152242.GC19782@crux.rdu.redhat.com","subject":"Re: [PATCH] remote: document the 'rm' subcommand","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-07T20:47:39Z","receivedAt":"2007-07-07T20:47:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Care to resend a three-patch series (implementation, this\ndocumentation, and test suite updates)?\n"},{"id":"47324","messageId":"7vtzs7juu5.fsf@assigned-by-dhcp.cox.net","threadId":"8457","inReplyTo":"7vodio6ivo.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] remote: document the 'rm' subcommand","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-14T07:41:22Z","receivedAt":"2007-07-14T07:41:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Care to resend a three-patch series (implementation, this\n> documentation, and test suite updates)?\n\nIt seems that this has to miss the boat for 1.5.3...\n"},{"id":"52333","messageId":"7vy7fojc3s.fsf@gitster.siamese.dyndns.org","threadId":"8457","inReplyTo":"11810859232541-git-send-email-jbowes@dangerouslyinc.com","subject":"Re: [PATCH] remote: add 'rm' subcommand","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-09-03T10:07:51Z","receivedAt":"2007-09-03T10:07:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"James Bowes <jbowes@dangerouslyinc.com> writes:\n\n> Introduce git-remote rm <name> which will:\n>  - Remove the remote config entry for <name>.\n>  - Remove any config entries for tracking branches of <name>.\n>  - Remove any stored remote branches of <name>.\n>\n> Signed-off-by: James Bowes <jbowes@dangerouslyinc.com>\n\nLet's continue with this in 1.5.4 cycle.  Together with Dscho's\n\"--mirror\" patch, this will make \"remote\" more complete.\n\n> If there is any interest in this, I'll follow up later with additions\n> to the docs.\n\nThis is not a good thing to say here.  If even the original\nauthor cannot be bothered to perfect it unconditionally (iow\neven when other people do not realize how useful it would be\ninitially and nobody seem to be interested), it does not help\nconvincing others that it is a good thing for the community to\ntake the patch.\n\n> +sub rm_remote {\n> +    my ($name) = @_;\n> +\tif (!exists $remote->{$name}) {\n> +\t\tprint STDERR \"No such remote $name\\n\";\n> +\t\treturn;\n> +\t}\n> +\n> +\t$git->command('config', '--remove-section', \"remote.$name\");\n> +\n> +\teval {\n> +\t    my @trackers = $git->command('config', '--get-regexp',\n> +\t\t\t'branch.*.remote', $name);\n\nIs this correct, or should it be '^branch\\..*\\.remote$'\n\n> +\t\tfor (@trackers) {\n> +\t\t\t/^branch\\.(.*)?\\.remote/;\n\nAnd this one.  Why do we have '?' there?  Perhaps...\n\n\tif (/^branch\\.(.*\\)\\.remote /) {\n\t\t$git->config('--unset', \"branch.$1.remote\");\n\t\t$git->config('--unset', \"branch.$1.merge\");\n\t} else {\n        \tdie \"Gaah, why $_ is not branch.<<name>>.remote???\"\n\t}\n\nWe seem to have another subroutine to prune remote tracking\nbranches, which does it slightly differently.  Maybe we would\nwant to share code with that codepath?\n\nOther than that, I think the patch is sane, with your later\n\"documentation patch\".\n\nWe would want a handful tests, including ones to check error\nconditions, such as trying to remove a remote that does not\nexist.\n"}]}