mirror of
https://github.com/git/git.git
synced 2024-10-28 21:07:52 +01:00
Teach 'git remote' how to cleanup stale tracking branches.
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>
This commit is contained in:
parent
7a8c9ec1a9
commit
859607dfe0
2 changed files with 43 additions and 1 deletions
|
@ -12,6 +12,7 @@ SYNOPSIS
|
||||||
'git-remote'
|
'git-remote'
|
||||||
'git-remote' add <name> <url>
|
'git-remote' add <name> <url>
|
||||||
'git-remote' show <name>
|
'git-remote' show <name>
|
||||||
|
'git-remote' prune <name>
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
|
@ -26,6 +27,10 @@ update remote-tracking branches <name>/<branch>.
|
||||||
|
|
||||||
In the third form, gives some information about the remote <name>.
|
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
|
The remote configuration is achieved using the `remote.origin.url` and
|
||||||
`remote.origin.fetch` configuration variables. (See
|
`remote.origin.fetch` configuration variables. (See
|
||||||
gitlink:git-config[1]).
|
gitlink:git-config[1]).
|
||||||
|
|
|
@ -200,7 +200,7 @@ sub show_mapping {
|
||||||
print " @$new\n";
|
print " @$new\n";
|
||||||
}
|
}
|
||||||
if (@$stale) {
|
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";
|
print " @$stale\n";
|
||||||
}
|
}
|
||||||
if (@$tracked) {
|
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 {
|
sub show_remote {
|
||||||
my ($name, $ls_remote) = @_;
|
my ($name, $ls_remote) = @_;
|
||||||
if (!exists $remote->{$name}) {
|
if (!exists $remote->{$name}) {
|
||||||
|
@ -270,6 +287,25 @@ sub add_remote {
|
||||||
show_remote($ARGV[$i], $ls_remote);
|
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') {
|
elsif ($ARGV[0] eq 'add') {
|
||||||
if (@ARGV != 3) {
|
if (@ARGV != 3) {
|
||||||
print STDERR "Usage: git remote add <name> <url>\n";
|
print STDERR "Usage: git remote add <name> <url>\n";
|
||||||
|
@ -281,5 +317,6 @@ sub add_remote {
|
||||||
print STDERR "Usage: git remote\n";
|
print STDERR "Usage: git remote\n";
|
||||||
print STDERR " git remote add <name> <url>\n";
|
print STDERR " git remote add <name> <url>\n";
|
||||||
print STDERR " git remote show <name>\n";
|
print STDERR " git remote show <name>\n";
|
||||||
|
print STDERR " git remote prune <name>\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue