diff options
author | Junio C Hamano <junkio@cox.net> | 2007-02-04 06:14:40 (GMT) |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-02-04 07:05:34 (GMT) |
commit | d77ee72662a821d66ae218056f0103eb24d8d4b4 (patch) | |
tree | e22abdbd11735a0669362f934ae723d233c87e2b /git-remote.perl | |
parent | eb8381c88518b10d683a29deea1d43ed671f14ec (diff) | |
parent | 8d0fc48f27304ac1bc7abf802ec53fe66fedb15a (diff) | |
download | git-d77ee72662a821d66ae218056f0103eb24d8d4b4.zip git-d77ee72662a821d66ae218056f0103eb24d8d4b4.tar.gz git-d77ee72662a821d66ae218056f0103eb24d8d4b4.tar.bz2 |
Merge branch 'master' into np/dreflog
This is to resolve conflicts early in preparation for possible
inclusion of "reflog on detached HEAD" series by Nico, as having
it in 1.5.0 would really help us remove confusion between
detached and attached states.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'git-remote.perl')
-rwxr-xr-x | git-remote.perl | 90 |
1 files changed, 65 insertions, 25 deletions
diff --git a/git-remote.perl b/git-remote.perl index fc055b6..f16ff21 100755 --- a/git-remote.perl +++ b/git-remote.perl @@ -64,7 +64,7 @@ sub list_remote { my ($git) = @_; my %seen = (); my @remotes = eval { - $git->command(qw(repo-config --get-regexp), '^remote\.'); + $git->command(qw(config --get-regexp), '^remote\.'); }; for (@remotes) { if (/^remote\.([^.]*)\.(\S*)\s+(.*)$/) { @@ -103,7 +103,7 @@ sub list_branch { my ($git) = @_; my %seen = (); my @branches = eval { - $git->command(qw(repo-config --get-regexp), '^branch\.'); + $git->command(qw(config --get-regexp), '^branch\.'); }; for (@branches) { if (/^branch\.([^.]*)\.(\S*)\s+(.*)$/) { @@ -130,7 +130,7 @@ sub update_ls_remote { $info->{'LS_REMOTE'} = \@ref; } -sub show_wildcard_mapping { +sub list_wildcard_mapping { my ($forced, $ours, $ls) = @_; my %refs; for (@$ls) { @@ -156,25 +156,14 @@ sub show_wildcard_mapping { push @tracked, $_; } } - if (@new) { - print " New remote branches (next fetch will store in remotes/$ours)\n"; - print " @new\n"; - } - if (@stale) { - print " Stale tracking branches in remotes/$ours (you'd better remove them)\n"; - print " @stale\n"; - } - if (@tracked) { - print " Tracked remote branches\n"; - print " @tracked\n"; - } + return \@new, \@stale, \@tracked; } -sub show_mapping { +sub list_mapping { my ($name, $info) = @_; my $fetch = $info->{'FETCH'}; my $ls = $info->{'LS_REMOTE'}; - my (@stale, @tracked); + my (@new, @stale, @tracked); for (@$fetch) { next unless (/(\+)?([^:]+):(.*)/); @@ -182,7 +171,11 @@ sub show_mapping { if ($theirs eq 'refs/heads/*' && $ours =~ /^refs\/remotes\/(.*)\/\*$/) { # wildcard mapping - show_wildcard_mapping($forced, $1, $ls); + my ($w_new, $w_stale, $w_tracked) + = list_wildcard_mapping($forced, $1, $ls); + push @new, @$w_new; + push @stale, @$w_stale; + push @tracked, @$w_tracked; } elsif ($theirs =~ /\*/ || $ours =~ /\*/) { print STDERR "Warning: unrecognized mapping in remotes.$name.fetch: $_\n"; @@ -196,13 +189,40 @@ sub show_mapping { } } } - if (@stale) { - print " Stale tracking branches in remotes/$name (you'd better remove them)\n"; - print " @stale\n"; + return \@new, \@stale, \@tracked; +} + +sub show_mapping { + my ($name, $info) = @_; + my ($new, $stale, $tracked) = list_mapping($name, $info); + if (@$new) { + print " New remote branches (next fetch will store in remotes/$name)\n"; + print " @$new\n"; } - if (@tracked) { + if (@$stale) { + print " Stale tracking branches in remotes/$name (use 'git remote prune')\n"; + print " @$stale\n"; + } + if (@$tracked) { print " Tracked remote branches\n"; - print " @tracked\n"; + print " @$tracked\n"; + } +} + +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]); } } @@ -238,8 +258,8 @@ sub add_remote { print STDERR "remote $name already exists.\n"; exit(1); } - $git->command('repo-config', "remote.$name.url", $url); - $git->command('repo-config', "remote.$name.fetch", + $git->command('config', "remote.$name.url", $url); + $git->command('config', "remote.$name.fetch", "+refs/heads/*:refs/remotes/$name/*"); } @@ -267,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"; @@ -278,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); } |