File: 16-reflog.t

package info (click to toggle)
libgit-raw-perl 0.79-7
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,448 kB
  • sloc: perl: 5,267; ansic: 182; makefile: 6
file content (93 lines) | stat: -rw-r--r-- 2,639 bytes parent folder | download | duplicates (2)
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
#!perl

use Test::More;

use Git::Raw;
use File::Spec::Functions qw(catfile rel2abs);

my $path = rel2abs(catfile('t', 'test_repo'));
my $repo = Git::Raw::Repository -> open($path);

my $master = Git::Raw::Branch -> lookup($repo, 'master', 1);
my $head = $master -> target;
isa_ok $head, 'Git::Raw::Commit';

my $branch_name = 'reflog_branch';

my $branch = $repo -> branch($branch_name, $head);
is $branch -> type, 'direct';
is $branch -> name, "refs/heads/$branch_name";

my $reflog = $branch -> reflog;
my @entries = $reflog -> entries;
is scalar(@entries), 1;

my $message = 'My entry';
$reflog -> append ($message);
$reflog -> write;
@entries = $reflog -> entries;
is scalar(@entries), 2;
is $reflog -> entry_count, 2;

ok (!eval { $reflog -> entries(0, 0) });
ok (!eval { $reflog -> entries(0, 3) });
ok (!eval { $reflog -> entries(1, 2) });
ok (!eval { $reflog -> entries(2, 1) });
ok (eval { $reflog -> entries(0, 2) });
ok (eval { $reflog -> entries(1, 1) });

my @entries2 = $reflog -> entries(0, 1);
is scalar(@entries2), 1;
is $entries2[0] -> message, $entries[0] -> message;

@entries2 = $reflog -> entries(1, 1);
is scalar(@entries2), 1;
is $entries2[0] -> message, $entries[1] -> message;

@entries2 = $reflog -> entries(0, 2);
is scalar(@entries2), 2;
is $entries2[0] -> message, $entries[0] -> message;
is $entries2[1] -> message, $entries[1] -> message;

is $entries[0] -> message, $message;
is $entries[0] -> new_id, $entries[0] -> old_id;
is $entries[0] -> old_id, $entries[1] -> new_id;
is $entries[0] -> committer -> name, $entries[1] -> committer -> name;
is $entries[0] -> committer -> email, $entries[1] -> committer -> email;
ok ($entries[0] -> committer -> time >= $entries[1] -> committer -> time);
is $entries[0] -> committer -> offset, $entries[1] -> committer -> offset;

my $name  = 'Committer';
my $email = 'committer@example.com';
my $time = time();
my $off  = 120;
my $me   = Git::Raw::Signature -> new($name, $email, $time, $off);

$reflog -> append ($message, $me);
$reflog -> write;
@entries = $reflog -> entries;
is scalar(@entries), 3;
is $entries[0] -> committer -> name, $name;
is $entries[0] -> committer -> email, $email;

$reflog -> drop (1);
$reflog -> write;
@entries = $reflog -> entries;
is scalar(@entries), 2;
is $entries[0] -> old_id, $entries[1] -> new_id;

$reflog -> delete;
$reflog = $branch -> reflog;
@entries = $reflog -> entries;
is scalar(@entries), 0;

$reflog = Git::Raw::Reflog -> open($branch);
@entries = $reflog -> entries;
is scalar(@entries), 0;

$reflog -> append ($message, $me);
$reflog -> write;
@entries = $reflog -> entries;
is scalar(@entries), 1;

done_testing;