{"thread":{"id":"6622","subject":"[PATCH 2/2] Teach 'git remote' how to cleanup stale tracking branches.","startedAt":"2007-02-02T05:06:08Z","lastAt":"2007-02-02T10:53:56Z","messageCount":4,"participants":["Shawn O. Pearce","Junio C Hamano","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"33335","messageId":"20070202050608.GB20505@spearce.org","threadId":"6622","inReplyTo":"58b74d176fd10417a58d42d9437c631d03f4c4f6.1170392736.git.spearce@spearce.org","subject":"[PATCH 2/2] Teach 'git remote' how to cleanup stale tracking branches.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-02-02T05:06:08Z","receivedAt":"2007-02-02T05:06:08Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Since it can be annoying to manually cleanup 40 tracking branches\nwhich were removed by the remote system, 'git remote prune <n>'\ncan now be used to delete any tracking branches under <n> which\nare no longer available on the remote system.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n\n Be nice if this made it into 1.5.0.  :-)\n\n Documentation/git-remote.txt |    5 +++++\n git-remote.perl              |   39 ++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 43 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt\nindex 358c1ac..817651e 100644\n--- a/Documentation/git-remote.txt\n+++ b/Documentation/git-remote.txt\n@@ -12,6 +12,7 @@ SYNOPSIS\n 'git-remote'\n 'git-remote' add <name> <url>\n 'git-remote' show <name>\n+'git-remote' prune <name>\n \n DESCRIPTION\n -----------\n@@ -26,6 +27,10 @@ update remote-tracking branches <name>/<branch>.\n \n In the third form, gives some information about the remote <name>.\n \n+In the fourth form, deletes all stale tracking branches under <name>.\n+These stale branches have already been removed from the remote repository\n+referenced by <name>, but are still locally available in \"remotes/<name>\".\n+\n The remote configuration is achieved using the `remote.origin.url` and\n `remote.origin.fetch` configuration variables.  (See\n gitlink:git-config[1]).\ndiff --git a/git-remote.perl b/git-remote.perl\nindex 969d33b..f16ff21 100755\n--- a/git-remote.perl\n+++ b/git-remote.perl\n@@ -200,7 +200,7 @@ sub show_mapping {\n \t\tprint \"    @$new\\n\";\n \t}\n \tif (@$stale) {\n-\t\tprint \"  Stale tracking branches in remotes/$name (you'd better remove them)\\n\";\n+\t\tprint \"  Stale tracking branches in remotes/$name (use 'git remote prune')\\n\";\n \t\tprint \"    @$stale\\n\";\n \t}\n \tif (@$tracked) {\n@@ -209,6 +209,23 @@ sub show_mapping {\n \t}\n }\n \n+sub prune_remote {\n+\tmy ($name, $ls_remote) = @_;\n+\tif (!exists $remote->{$name}) {\n+\t\tprint STDERR \"No such remote $name\\n\";\n+\t\treturn;\n+\t}\n+\tmy $info = $remote->{$name};\n+\tupdate_ls_remote($ls_remote, $info);\n+\n+\tmy ($new, $stale, $tracked) = list_mapping($name, $info);\n+\tmy $prefix = \"refs/remotes/$name\";\n+\tforeach my $to_prune (@$stale) {\n+\t\tmy @v = $git->command(qw(rev-parse --verify), \"$prefix/$to_prune\");\n+\t\t$git->command(qw(update-ref -d), \"$prefix/$to_prune\", $v[0]);\n+\t}\n+}\n+\n sub show_remote {\n \tmy ($name, $ls_remote) = @_;\n \tif (!exists $remote->{$name}) {\n@@ -270,6 +287,25 @@ elsif ($ARGV[0] eq 'show') {\n \t\tshow_remote($ARGV[$i], $ls_remote);\n \t}\n }\n+elsif ($ARGV[0] eq 'prune') {\n+\tmy $ls_remote = 1;\n+\tmy $i;\n+\tfor ($i = 1; $i < @ARGV; $i++) {\n+\t\tif ($ARGV[$i] eq '-n') {\n+\t\t\t$ls_remote = 0;\n+\t\t}\n+\t\telse {\n+\t\t\tlast;\n+\t\t}\n+\t}\n+\tif ($i >= @ARGV) {\n+\t\tprint STDERR \"Usage: git remote prune <remote>\\n\";\n+\t\texit(1);\n+\t}\n+\tfor (; $i < @ARGV; $i++) {\n+\t\tprune_remote($ARGV[$i], $ls_remote);\n+\t}\n+}\n elsif ($ARGV[0] eq 'add') {\n \tif (@ARGV != 3) {\n \t\tprint STDERR \"Usage: git remote add <name> <url>\\n\";\n@@ -281,5 +317,6 @@ else {\n \tprint STDERR \"Usage: git remote\\n\";\n \tprint STDERR \"       git remote add <name> <url>\\n\";\n \tprint STDERR \"       git remote show <name>\\n\";\n+\tprint STDERR \"       git remote prune <name>\\n\";\n \texit(1);\n }\n-- \n1.5.0.rc3.1.ge4b0e\n"},{"id":"33340","messageId":"7v4pq5ks9i.fsf@assigned-by-dhcp.cox.net","threadId":"6622","inReplyTo":"20070202050608.GB20505@spearce.org","subject":"Re: [PATCH 2/2] Teach 'git remote' how to cleanup stale tracking branches.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-02T06:06:33Z","receivedAt":"2007-02-02T06:06:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"If you are disconnected, would it fail gracefully without\nremoving stuff?  From a cursory look it should, but just making\nsure.\n"},{"id":"33341","messageId":"20070202061359.GB20719@spearce.org","threadId":"6622","inReplyTo":"7v4pq5ks9i.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 2/2] Teach 'git remote' how to cleanup stale tracking branches.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-02-02T06:13:59Z","receivedAt":"2007-02-02T06:13:59Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> If you are disconnected, would it fail gracefully without\n> removing stuff?  From a cursory look it should, but just making\n> sure.\n\nIndeed, it crashes out:\n \n\t$ ./git-remote prune cs-src\n\tssh: host.that.exists: No address associated with nodename\n\tfatal: The remote end hung up unexpectedly\n\tls-remote --heads cs:sw/src/git: command returned error: 1\n\t[git (sp/remote)]$ ls .git/refs/remotes/cs-src/\n\t.       ..      master\n\nand the refs are still safe.\n\n-- \nShawn.\n"},{"id":"33371","messageId":"epv55j$8js$1@sea.gmane.org","threadId":"6622","inReplyTo":"20070202050608.GB20505@spearce.org","subject":"Re: [PATCH 2/2] Teach 'git remote' how to cleanup stale tracking branches.","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-02-02T10:53:56Z","receivedAt":"2007-02-02T10:53:56Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Shawn O. Pearce wrote:\n\n\n> diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt\n> index 358c1ac..817651e 100644\n> --- a/Documentation/git-remote.txt\n> +++ b/Documentation/git-remote.txt\n> @@ -12,6 +12,7 @@ SYNOPSIS\n>  'git-remote'\n>  'git-remote' add <name> <url>\n>  'git-remote' show <name>\n> +'git-remote' prune <name>\n>  \n>  DESCRIPTION\n>  -----------\n> @@ -26,6 +27,10 @@ update remote-tracking branches <name>/<branch>.\n>  \n>  In the third form, gives some information about the remote <name>.\n>  \n> +In the fourth form, deletes all stale tracking branches under <name>.\n> +These stale branches have already been removed from the remote repository\n> +referenced by <name>, but are still locally available in \"remotes/<name>\".\n> +\n\nWouldn't it be better to refer to subcommand by name, instead of\nthe number of subcommand (\"fourth form\")? Compare git-rerere(1).\n\nP.S. I wanted to refer to documentation of other commands with\nsubcommands, but git-bisect(1) is not good example; git-rerere(1)\nI think is.\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"}]}