aboutsummaryrefslogtreecommitdiff
path: root/t/11-git.t
blob: 03228729e5d3c541039761278e0f1384e6c0082c (plain)
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
102
103
104
#!/usr/bin/env perl

use 5.16.0;
use strict;
use warnings FATAL => 'all';
use Test::More;
use Capture::Tiny qw/ capture_merged /;
use FindBin '$RealBin';
use lib $RealBin;
use Test::Sbotools qw/ set_gpg_verify set_repo sbosnap /;

if ($ENV{TEST_INSTALL}) {
	plan tests => 5;
} else {
	plan skip_all => 'Only run these tests if TEST_INSTALL=1';
}

sub cleanup {
    capture_merged {
      system(qw!rm -rf !, "/tmp/gitrepo");
      if (defined $ENV{TRAVIS} and $ENV{TRAVIS} eq 'true') {
        system(qw!userdel test!);
        system(qw!groupdel test!);
      }
    };
}

sub slurp {
	my $file = shift;
	local $/;
	open my $fh, '<', $file or return undef;
	my $contents = <$fh>;
	return $contents;
}

cleanup();

# initialise repo
capture_merged { system(<<"END"); };
rm -fr /tmp/gitrepo;
mkdir -p /tmp/gitrepo;
cd /tmp/gitrepo;

git init;
echo -n "Hello" > test;
git add test;
git commit -m 'initial';

git checkout -b b1;
echo -n "Hello World." > test;
git commit -am 'branch commit';

git checkout master;
echo -n "Hello World" > test;
git commit -am 'master commit';
END

if (defined $ENV{TRAVIS} and $ENV{TRAVIS} eq 'true') {
capture_merged { system(<<"END"); };
groupadd -g 199 test
useradd -u 199 -g 199 -d /tmp test
chown -R 199:199 /tmp/gitrepo

git config --system --add safe.directory /tmp/gitrepo/.git
END
}

set_gpg_verify('FALSE');
set_repo("/tmp/gitrepo/");

# 1: sbosnap get initial repo
sbosnap 'fetch', { expected => qr!Pulling SlackBuilds tree.*Cloning into '/usr/sbo/repo'!s };

# 2-3: check ownership of repodir if under TRAVIS
SKIP: {
  skip "Only run under Travis CI", 2 unless defined $ENV{TRAVIS} and $ENV{TRAVIS} eq 'true';

  my @fnames = glob "/tmp/gitrepo/.git/objects/*/*";

  my @stat = stat shift @fnames;
  is ($stat[4], 199, "Correct owner uid for /tmp/gitrepo");
  is ($stat[5], 199, "Correct owner gid for /tmp/gitrepo");
}

# make a conflict
capture_merged { system(<<"END"); };
cd /tmp/gitrepo
if find /tmp/gitrepo . -maxdepth 0 -user test; then
  sudo -u test git reset --hard b1
else
  git reset --hard b1
fi
END

# 4: sbosnap update through merge conflict
sbosnap 'update', { expected => qr!Updating SlackBuilds tree.*master.*->.*origin/master.*forced update.*HEAD is now at!s };

# 5: make sure test repo is merged correctly
is (slurp('/usr/sbo/repo/test'), 'Hello World.', 'repo test file updated correctly');

# Cleanup
END {
	cleanup();
}