-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitsync.pl
48 lines (40 loc) · 1.26 KB
/
gitsync.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
#!/usr/bin/perl
#
# Comments are marked with a Hash (#)
#
# Config Syntax:
# [id which is used for directory]: [src repo] -> [dest repo]
#
# Example:
# BeatTheWeight: [email protected]:apps/BeatTheWeight.git -> [email protected]:maximilianvoss/BeatTheWeight.git
use strict;
open ( CONFIG, 'gitsync.config');
while ( my $line = <CONFIG> ) {
unless ( $line =~ /^\s*#/ || $line =~ /^\s*$/ ) {
$line =~ /\s*(\w+):\s*(.+)\s*-\>\s*(.+)\s*$/;
my $id = $1;
my $src = $2;
my $dest = $3;
print "Syncing: $id\n";
unless ( -e $id ) {
my $cmd = "git clone $src $id";
print 'Initial clone of git repository: ' . $cmd . "\n";
print `$cmd`;
my $cmd = "(cd $id; git remote add dest $dest)";
print 'Setting the destination remote: ' . $cmd . "\n";
print `$cmd`;
}
my $cmd = "cd $id; git fetch --all -p; git branch -a";
print 'Finding all remote branches: ' . $cmd . "\n";
my @result = `$cmd`;
for ( my $i; $i < @result; $i++ ) {
if ( $result[$i] =~ /^\s*remotes\/origin\/(.+)/ && $result[$i] !~ /->/ ) {
my $branch = $1;
my $cmd = "(cd $id; git checkout $branch; git pull --all; git pull origin $branch; git push dest --all; git push dest --tags)";
print 'Syncing the repositories: ' . $cmd . "\n";
print `$cmd`;
}
}
}
}
close (CONFIG);