-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathUtils.pm
88 lines (68 loc) · 1.72 KB
/
Utils.pm
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
package Utils;
require Exporter;
use base qw/Exporter/;
use strict;
use warnings;
our $tempdir = q{/tmp/git-backup-tests};
our $command = q{../git-inc-backup.pl};
our $source = qq{$tempdir/source};
our $backup = qq{$tempdir/backup};
our $restore = qq{$tempdir/restore};
our $sourcegit = qq{${source}/.git};
our @EXPORT = qw/cmd add_file compare_repos get_branches get_log $tempdir $command $source $backup $restore $sourcegit/;
sub cmd($)
{
my ($s) = @_;
print "[$s]\n";
if (wantarray) {
my @r = `$s`;
print @r;
return @r;
} else {
my $r = `$s`;
print $r;
return $r;
}
}
sub add_file
{
my ($file) = @_;
cmd qq{echo 1 > $source/$file};
cmd qq{git --git-dir $sourcegit --work-tree $source add $file};
cmd qq{git --git-dir $sourcegit commit -m "$file"};
}
sub compare_repos
{
my ($a, $b) = @_;
my @branch_a = get_branches($a);
my @branch_b = get_branches($b);
die unless @branch_a;
die unless scalar @branch_a == scalar @branch_b;
#use Data::Dumper;
#die Dumper(\@branch_a);
for (1..scalar @branch_a) {
my $a_branch = shift @branch_a;
my $b_branch = shift @branch_b;
die "$a_branch eq $b_branch" unless $a_branch eq $b_branch;
my @a_log = get_log($a, $a_branch);
my @b_log = get_log($b, $a_branch);
die unless scalar @a_log == scalar @b_log;
for (1..scalar @a_log) {
my $a_l = shift @a_log;
my $b_l = shift @b_log;
die unless $a_l eq $b_l;
}
}
}
sub get_branches
{
my ($a) = @_;
sort map { /^[\s\*]*(.*)$/; $1 } cmd qq{git --git-dir $a/.git --work-tree $a/.git branch};
}
sub get_log
{
my ($a, $branch) = @_;
cmd qq{git --git-dir $a/.git --work-tree $a/.git checkout $branch};
cmd qq{git --git-dir $a/.git --work-tree $a/.git log --no-color --format=oneline};
}
1;