-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitolite-fetch-all-repositories.pl
executable file
·81 lines (64 loc) · 1.51 KB
/
gitolite-fetch-all-repositories.pl
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
#!/usr/bin/perl -w
#
# gitolite-fetch-all-repositories.pl
#
# Developed by Lubomir Host <[email protected]>
# Licensed under terms of GNU General Public License.
# All rights reserved.
#
# Changelog:
# 2016-11-13 - created
#
use strict;
use JSON qw (from_json);
#use Data::Dumper;
use Cwd;
$| = 1;
my $git_repo = shift;
unless ($git_repo) {
if (-f "REPO") {
open (REPO, '<REPO') or die "Can't open 'REPO': $!";
while (my $line = <REPO>) {
next if ($line =~ m/^\s*#/
or $line =~ m/^\s*$/
);
chomp($line);
$git_repo = $line;
last if (defined($git_repo))
}
close (REPO);
}
}
print "REPO = '$git_repo'\n";
unless ($git_repo) {
print STDERR "Usage: $0 <path-to-your-git-repository>\n";
print STDERR " echo '<path-to-your-git-repository>' > REPO\n";
exit 1;
}
my $git_json;
{
local $/;
open (GIT, "/usr/bin/ssh $git_repo info --json |");
$git_json = <GIT>;
close (GIT);
}
#print Dumper($git_json, from_json($git_json));
my $ginfo = from_json($git_json);
my $cwd = getcwd();
foreach my $repo (sort keys %{$ginfo->{repos}}) {
print "------- Repository: $repo\n";
chdir $cwd || die "Can't change directory: $!";
if (-d $repo) {
chdir "$cwd/$repo";
system(qw( git fetch --all ));
}
elsif ($repo =~ m/^[a-z0-9_:\.\/\+-]+$/i && $repo !~ m(/\.\./) ) {
mkdir "$repo" || die "Can't create directory: $!";
print "\tMISSING\n";
system(qw( git clone ), "$git_repo:$repo", "$repo");
}
else {
print "\tMISSING but ignored (wildcard chars)\n";
}
}
# vim: ts=4 fdm=marker fdl=0 fdc=3