Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
git-mirror
/
git
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
0
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security
Insights
Files
8b5157e
Documentation
arm
compat
contrib
gitweb
mozilla-sha1
perl
ppc
t
templates
xdiff
.gitignore
.mailmap
COPYING
GIT-VERSION-GEN
INSTALL
Makefile
README
alloc.c
archive-tar.c
archive-zip.c
archive.h
base85.c
blob.c
blob.h
builtin-add.c
builtin-annotate.c
builtin-apply.c
builtin-archive.c
builtin-blame.c
builtin-branch.c
builtin-cat-file.c
builtin-check-ref-format.c
builtin-checkout-index.c
builtin-commit-tree.c
builtin-count-objects.c
builtin-describe.c
builtin-diff-files.c
builtin-diff-index.c
builtin-diff-stages.c
builtin-diff-tree.c
builtin-diff.c
builtin-fmt-merge-msg.c
builtin-for-each-ref.c
builtin-grep.c
builtin-init-db.c
builtin-log.c
builtin-ls-files.c
builtin-ls-tree.c
builtin-mailinfo.c
builtin-mailsplit.c
builtin-merge-file.c
builtin-mv.c
builtin-name-rev.c
builtin-pack-objects.c
builtin-pack-refs.c
builtin-prune-packed.c
builtin-prune.c
builtin-push.c
builtin-read-tree.c
builtin-reflog.c
builtin-repo-config.c
builtin-rerere.c
builtin-rev-list.c
builtin-rev-parse.c
builtin-rm.c
builtin-runstatus.c
builtin-shortlog.c
builtin-show-branch.c
builtin-show-ref.c
builtin-stripspace.c
builtin-symbolic-ref.c
builtin-tar-tree.c
builtin-unpack-objects.c
builtin-update-index.c
builtin-update-ref.c
builtin-upload-archive.c
builtin-verify-pack.c
builtin-write-tree.c
builtin.h
cache-tree.c
cache-tree.h
cache.h
check-builtins.sh
check-racy.c
color.c
color.h
combine-diff.c
commit.c
commit.h
config.c
config.mak.in
configure.ac
connect.c
convert-objects.c
copy.c
csum-file.c
csum-file.h
ctype.c
daemon.c
date.c
delta.h
diff-delta.c
diff-lib.c
diff.c
diff.h
diffcore-break.c
diffcore-delta.c
diffcore-order.c
diffcore-pickaxe.c
diffcore-rename.c
diffcore.h
dir.c
dir.h
dump-cache-tree.c
entry.c
environment.c
exec_cmd.c
exec_cmd.h
fetch-pack.c
fetch.c
fetch.h
fsck-objects.c
generate-cmdlist.sh
git-add--interactive.perl
git-am.sh
git-applymbox.sh
git-applypatch.sh
git-archimport.perl
git-bisect.sh
git-checkout.sh
git-clean.sh
git-clone.sh
git-commit.sh
git-compat-util.h
git-cvsexportcommit.perl
git-cvsimport.perl
git-cvsserver.perl
git-fetch.sh
git-gc.sh
git-instaweb.sh
git-lost-found.sh
git-ls-remote.sh
git-merge-octopus.sh
git-merge-one-file.sh
git-merge-ours.sh
git-merge-resolve.sh
git-merge-stupid.sh
git-merge.sh
git-p4import.py
git-parse-remote.sh
git-pull.sh
git-quiltimport.sh
git-rebase.sh
git-relink.perl
git-remote.perl
git-repack.sh
git-request-pull.sh
git-reset.sh
git-resolve.sh
git-revert.sh
git-send-email.perl
git-sh-setup.sh
git-svn.perl
git-svnimport.perl
git-tag.sh
git-verify-tag.sh
git.c
git.spec.in
gitk
grep.c
grep.h
hash-object.c
help.c
http-fetch.c
http-push.c
http.c
http.h
ident.c
imap-send.c
index-pack.c
interpolate.c
interpolate.h
list-objects.c
list-objects.h
local-fetch.c
lockfile.c
log-tree.c
log-tree.h
merge-base.c
merge-file.c
merge-index.c
merge-recursive.c
merge-tree.c
mktag.c
mktree.c
object-refs.c
object.c
object.h
pack-check.c
pack-redundant.c
pack.h
pager.c
patch-delta.c
patch-id.c
path-list.c
path-list.h
path.c
peek-remote.c
pkt-line.c
pkt-line.h
quote.c
quote.h
reachable.c
reachable.h
read-cache.c
receive-pack.c
reflog-walk.c
reflog-walk.h
refs.c
refs.h
revision.c
revision.h
rsh.c
rsh.h
run-command.c
run-command.h
send-pack.c
server-info.c
setup.c
sha1_file.c
sha1_name.c
shallow.c
shell.c
show-index.c
sideband.c
sideband.h
ssh-fetch.c
ssh-pull.c
ssh-push.c
ssh-upload.c
strbuf.c
strbuf.h
tag.c
tag.h
tar.h
test-date.c
test-delta.c
test-sha1.c
test-sha1.sh
trace.c
tree-diff.c
tree-walk.c
tree-walk.h
tree.c
tree.h
unpack-file.c
unpack-trees.c
unpack-trees.h
update-server-info.c
upload-pack.c
usage.c
utf8.c
utf8.h
var.c
write_or_die.c
wt-status.c
wt-status.h
xdiff-interface.c
xdiff-interface.h
Breadcrumbs
git
/
git-remote.perl
Blame
Blame
Latest commit
History
History
executable file
·
282 lines (260 loc) · 6 KB
Breadcrumbs
git
/
git-remote.perl
Top
File metadata and controls
Code
Blame
executable file
·
282 lines (260 loc) · 6 KB
Raw
#!/usr/bin/perl -w use Git; my $git = Git->repository(); sub add_remote_config { my ($hash, $name, $what, $value) = @_; if ($what eq 'url') { if (exists $hash->{$name}{'URL'}) { print STDERR "Warning: more than one remote.$name.url\n"; } $hash->{$name}{'URL'} = $value; } elsif ($what eq 'fetch') { $hash->{$name}{'FETCH'} ||= []; push @{$hash->{$name}{'FETCH'}}, $value; } if (!exists $hash->{$name}{'SOURCE'}) { $hash->{$name}{'SOURCE'} = 'config'; } } sub add_remote_remotes { my ($hash, $file, $name) = @_; if (exists $hash->{$name}) { $hash->{$name}{'WARNING'} = 'ignored due to config'; return; } my $fh; if (!open($fh, '<', $file)) { print STDERR "Warning: cannot open $file\n"; return; } my $it = { 'SOURCE' => 'remotes' }; $hash->{$name} = $it; while (<$fh>) { chomp; if (/^URL:\s*(.*)$/) { # Having more than one is Ok -- it is used for push. if (! exists $it->{'URL'}) { $it->{'URL'} = $1; } } elsif (/^Push:\s*(.*)$/) { ; # later } elsif (/^Pull:\s*(.*)$/) { $it->{'FETCH'} ||= []; push @{$it->{'FETCH'}}, $1; } elsif (/^\#/) { ; # ignore } else { print STDERR "Warning: funny line in $file: $_\n"; } } close($fh); } sub list_remote { my ($git) = @_; my %seen = (); my @remotes = eval { $git->command(qw(repo-config --get-regexp), '^remote\.'); }; for (@remotes) { if (/^remote\.([^.]*)\.(\S*)\s+(.*)$/) { add_remote_config(\%seen, $1, $2, $3); } } my $dir = $git->repo_path() . "/remotes"; if (opendir(my $dh, $dir)) { local $_; while ($_ = readdir($dh)) { chomp; next if (! -f "$dir/$_" || ! -r _); add_remote_remotes(\%seen, "$dir/$_", $_); } } return \%seen; } sub add_branch_config { my ($hash, $name, $what, $value) = @_; if ($what eq 'remote') { if (exists $hash->{$name}{'REMOTE'}) { print STDERR "Warning: more than one branch.$name.remote\n"; } $hash->{$name}{'REMOTE'} = $value; } elsif ($what eq 'merge') { $hash->{$name}{'MERGE'} ||= []; push @{$hash->{$name}{'MERGE'}}, $value; } } sub list_branch { my ($git) = @_; my %seen = (); my @branches = eval { $git->command(qw(repo-config --get-regexp), '^branch\.'); }; for (@branches) { if (/^branch\.([^.]*)\.(\S*)\s+(.*)$/) { add_branch_config(\%seen, $1, $2, $3); } } return \%seen; } my $remote = list_remote($git); my $branch = list_branch($git); sub update_ls_remote { my ($harder, $info) = @_; return if (($harder == 0) || (($harder == 1) && exists $info->{'LS_REMOTE'})); my @ref = map { s|^[0-9a-f]{40}\s+refs/heads/||; $_; } $git->command(qw(ls-remote --heads), $info->{'URL'}); $info->{'LS_REMOTE'} = \@ref; } sub show_wildcard_mapping { my ($forced, $ours, $ls) = @_; my %refs; for (@$ls) { $refs{$_} = 01; # bit #0 to say "they have" } for ($git->command('for-each-ref', "refs/remotes/$ours")) { chomp; next unless (s|^[0-9a-f]{40}\s[a-z]+\srefs/remotes/$ours/||); next if ($_ eq 'HEAD'); $refs{$_} ||= 0; $refs{$_} |= 02; # bit #1 to say "we have" } my (@new, @stale, @tracked); for (sort keys %refs) { my $have = $refs{$_}; if ($have == 1) { push @new, $_; } elsif ($have == 2) { push @stale, $_; } elsif ($have == 3) { 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"; } } sub show_mapping { my ($name, $info) = @_; my $fetch = $info->{'FETCH'}; my $ls = $info->{'LS_REMOTE'}; my (@stale, @tracked); for (@$fetch) { next unless (/(\+)?([^:]+):(.*)/); my ($forced, $theirs, $ours) = ($1, $2, $3); if ($theirs eq 'refs/heads/*' && $ours =~ /^refs\/remotes\/(.*)\/\*$/) { # wildcard mapping show_wildcard_mapping($forced, $1, $ls); } elsif ($theirs =~ /\*/ || $ours =~ /\*/) { print STDERR "Warning: unrecognized mapping in remotes.$name.fetch: $_\n"; } elsif ($theirs =~ s|^refs/heads/||) { if (!grep { $_ eq $theirs } @$ls) { push @stale, $theirs; } elsif ($ours ne '') { push @tracked, $theirs; } } } if (@stale) { print " Stale tracking branches in remotes/$name (you'd better remove them)\n"; print " @stale\n"; } if (@tracked) { print " Tracked remote branches\n"; print " @tracked\n"; } } sub show_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); print "* remote $name\n"; print " URL: $info->{'URL'}\n"; for my $branchname (sort keys %$branch) { next if ($branch->{$branchname}{'REMOTE'} ne $name); my @merged = map { s|^refs/heads/||; $_; } split(' ',"@{$branch->{$branchname}{'MERGE'}}"); next unless (@merged); print " Remote branch(es) merged with 'git pull' while on branch $branchname\n"; print " @merged\n"; } if ($info->{'LS_REMOTE'}) { show_mapping($name, $info); } } sub add_remote { my ($name, $url) = @_; if (exists $remote->{$name}) { print STDERR "remote $name already exists.\n"; exit(1); } $git->command('repo-config', "remote.$name.url", $url); $git->command('repo-config', "remote.$name.fetch", "+refs/heads/*:refs/remotes/$name/*"); } if (!@ARGV) { for (sort keys %$remote) { print "$_\n"; } } elsif ($ARGV[0] eq 'show') { 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 show <remote>\n"; exit(1); } for (; $i < @ARGV; $i++) { show_remote($ARGV[$i], $ls_remote); } } elsif ($ARGV[0] eq 'add') { if (@ARGV != 3) { print STDERR "Usage: git remote add <name> <url>\n"; exit(1); } add_remote($ARGV[1], $ARGV[2]); } else { print STDERR "Usage: git remote\n"; print STDERR " git remote add <name> <url>\n"; print STDERR " git remote show <name>\n"; exit(1); }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
You can’t perform that action at this time.