summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7a8c9ec)
raw | patch | inline | side by side (parent: 7a8c9ec)
author | Shawn O. Pearce <spearce@spearce.org> | |
Fri, 2 Feb 2007 05:06:08 +0000 (00:06 -0500) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Fri, 2 Feb 2007 06:06:36 +0000 (22:06 -0800) |
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>
Signed-off-by: Junio C Hamano <junkio@cox.net>
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>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Documentation/git-remote.txt | patch | blob | history | |
git-remote.perl | patch | blob | history |
index 358c1acfc393f5c94ecf34c372c8f492b016f2ce..817651eaa443b2fdc527cb3955421c1f9a825373 100644 (file)
'git-remote'
'git-remote' add <name> <url>
'git-remote' show <name>
+'git-remote' prune <name>
DESCRIPTION
-----------
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 969d33bc5e7ab321d4462dbb246e471e22b451d1..f16ff21b8bed7fe4bc250a2489267ec8bb6ae00c 100755 (executable)
--- a/git-remote.perl
+++ b/git-remote.perl
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) {
}
}
+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}) {
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";
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);
}