* [PATCH 2/2] Teach 'git remote' how to cleanup stale tracking branches. [not found] <58b74d176fd10417a58d42d9437c631d03f4c4f6.1170392736.git.spearce@spearce.org> @ 2007-02-02 5:06 ` Shawn O. Pearce 2007-02-02 6:06 ` Junio C Hamano 2007-02-02 10:53 ` Jakub Narebski 0 siblings, 2 replies; 4+ messages in thread From: Shawn O. Pearce @ 2007-02-02 5:06 UTC (permalink / raw) To: Junio C Hamano; +Cc: git Since it can be annoying to manually cleanup 40 tracking branches which were removed by the remote system, 'git remote prune <n>' can now be used to delete any tracking branches under <n> which are no longer available on the remote system. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> --- Be nice if this made it into 1.5.0. :-) Documentation/git-remote.txt | 5 +++++ git-remote.perl | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletions(-) diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt index 358c1ac..817651e 100644 --- a/Documentation/git-remote.txt +++ b/Documentation/git-remote.txt @@ -12,6 +12,7 @@ SYNOPSIS 'git-remote' 'git-remote' add <name> <url> 'git-remote' show <name> +'git-remote' prune <name> DESCRIPTION ----------- @@ -26,6 +27,10 @@ update remote-tracking branches <name>/<branch>. In the third form, gives some information about the remote <name>. +In the fourth form, deletes all stale tracking branches under <name>. +These stale branches have already been removed from the remote repository +referenced by <name>, but are still locally available in "remotes/<name>". + The remote configuration is achieved using the `remote.origin.url` and `remote.origin.fetch` configuration variables. (See gitlink:git-config[1]). diff --git a/git-remote.perl b/git-remote.perl index 969d33b..f16ff21 100755 --- a/git-remote.perl +++ b/git-remote.perl @@ -200,7 +200,7 @@ sub show_mapping { print " @$new\n"; } if (@$stale) { - print " Stale tracking branches in remotes/$name (you'd better remove them)\n"; + print " Stale tracking branches in remotes/$name (use 'git remote prune')\n"; print " @$stale\n"; } if (@$tracked) { @@ -209,6 +209,23 @@ sub show_mapping { } } +sub prune_remote { + my ($name, $ls_remote) = @_; + if (!exists $remote->{$name}) { + print STDERR "No such remote $name\n"; + return; + } + my $info = $remote->{$name}; + update_ls_remote($ls_remote, $info); + + my ($new, $stale, $tracked) = list_mapping($name, $info); + my $prefix = "refs/remotes/$name"; + foreach my $to_prune (@$stale) { + my @v = $git->command(qw(rev-parse --verify), "$prefix/$to_prune"); + $git->command(qw(update-ref -d), "$prefix/$to_prune", $v[0]); + } +} + sub show_remote { my ($name, $ls_remote) = @_; if (!exists $remote->{$name}) { @@ -270,6 +287,25 @@ elsif ($ARGV[0] eq 'show') { show_remote($ARGV[$i], $ls_remote); } } +elsif ($ARGV[0] eq 'prune') { + my $ls_remote = 1; + my $i; + for ($i = 1; $i < @ARGV; $i++) { + if ($ARGV[$i] eq '-n') { + $ls_remote = 0; + } + else { + last; + } + } + if ($i >= @ARGV) { + print STDERR "Usage: git remote prune <remote>\n"; + exit(1); + } + for (; $i < @ARGV; $i++) { + prune_remote($ARGV[$i], $ls_remote); + } +} elsif ($ARGV[0] eq 'add') { if (@ARGV != 3) { print STDERR "Usage: git remote add <name> <url>\n"; @@ -281,5 +317,6 @@ else { print STDERR "Usage: git remote\n"; print STDERR " git remote add <name> <url>\n"; print STDERR " git remote show <name>\n"; + print STDERR " git remote prune <name>\n"; exit(1); } -- 1.5.0.rc3.1.ge4b0e ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] Teach 'git remote' how to cleanup stale tracking branches. 2007-02-02 5:06 ` [PATCH 2/2] Teach 'git remote' how to cleanup stale tracking branches Shawn O. Pearce @ 2007-02-02 6:06 ` Junio C Hamano 2007-02-02 6:13 ` Shawn O. Pearce 2007-02-02 10:53 ` Jakub Narebski 1 sibling, 1 reply; 4+ messages in thread From: Junio C Hamano @ 2007-02-02 6:06 UTC (permalink / raw) To: Shawn O. Pearce; +Cc: git If you are disconnected, would it fail gracefully without removing stuff? From a cursory look it should, but just making sure. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] Teach 'git remote' how to cleanup stale tracking branches. 2007-02-02 6:06 ` Junio C Hamano @ 2007-02-02 6:13 ` Shawn O. Pearce 0 siblings, 0 replies; 4+ messages in thread From: Shawn O. Pearce @ 2007-02-02 6:13 UTC (permalink / raw) To: Junio C Hamano; +Cc: git Junio C Hamano <junkio@cox.net> wrote: > If you are disconnected, would it fail gracefully without > removing stuff? From a cursory look it should, but just making > sure. Indeed, it crashes out: $ ./git-remote prune cs-src ssh: host.that.exists: No address associated with nodename fatal: The remote end hung up unexpectedly ls-remote --heads cs:sw/src/git: command returned error: 1 [git (sp/remote)]$ ls .git/refs/remotes/cs-src/ . .. master and the refs are still safe. -- Shawn. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] Teach 'git remote' how to cleanup stale tracking branches. 2007-02-02 5:06 ` [PATCH 2/2] Teach 'git remote' how to cleanup stale tracking branches Shawn O. Pearce 2007-02-02 6:06 ` Junio C Hamano @ 2007-02-02 10:53 ` Jakub Narebski 1 sibling, 0 replies; 4+ messages in thread From: Jakub Narebski @ 2007-02-02 10:53 UTC (permalink / raw) To: git Shawn O. Pearce wrote: > diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt > index 358c1ac..817651e 100644 > --- a/Documentation/git-remote.txt > +++ b/Documentation/git-remote.txt > @@ -12,6 +12,7 @@ SYNOPSIS > 'git-remote' > 'git-remote' add <name> <url> > 'git-remote' show <name> > +'git-remote' prune <name> > > DESCRIPTION > ----------- > @@ -26,6 +27,10 @@ update remote-tracking branches <name>/<branch>. > > In the third form, gives some information about the remote <name>. > > +In the fourth form, deletes all stale tracking branches under <name>. > +These stale branches have already been removed from the remote repository > +referenced by <name>, but are still locally available in "remotes/<name>". > + Wouldn't it be better to refer to subcommand by name, instead of the number of subcommand ("fourth form")? Compare git-rerere(1). P.S. I wanted to refer to documentation of other commands with subcommands, but git-bisect(1) is not good example; git-rerere(1) I think is. -- Jakub Narebski Warsaw, Poland ShadeHawk on #git ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-02-02 10:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <58b74d176fd10417a58d42d9437c631d03f4c4f6.1170392736.git.spearce@spearce.org>
2007-02-02 5:06 ` [PATCH 2/2] Teach 'git remote' how to cleanup stale tracking branches Shawn O. Pearce
2007-02-02 6:06 ` Junio C Hamano
2007-02-02 6:13 ` Shawn O. Pearce
2007-02-02 10:53 ` Jakub Narebski
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).