File: 03-tag.t

package info (click to toggle)
libgit-raw-perl 0.90%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,540 kB
  • sloc: perl: 5,432; ansic: 182; makefile: 6
file content (103 lines) | stat: -rw-r--r-- 2,303 bytes parent folder | download | duplicates (4)
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
#!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 $config = $repo -> config;
my $name   = $config -> str('user.name');
my $email  = $config -> str('user.email');

my $time = time();
my $off  = 120;
my $me   = Git::Raw::Signature -> new($name, $email, $time, $off);

my $commit = $repo -> head -> target;

isa_ok $commit, 'Git::Raw::Commit';

my $tag_name = 'v0.1';
my $tag_msg  = 'Initial version';

my $tag = $repo -> tag($tag_name, $tag_msg, $me, $commit);

is $tag -> name, $tag_name;
is $tag -> message, $tag_msg;

my $repo2 = $tag -> owner;
isa_ok $repo2, 'Git::Raw::Repository';
is $repo2 -> path, $repo -> path;

my $non_existent = Git::Raw::Tag -> lookup($repo, '123456789987654321');
is $non_existent, undef;

my $counter = 0;
eval { Git::Raw::Tag -> foreach($repo, sub { 1; }) };
ok (!$@);

Git::Raw::Tag -> foreach($repo, sub { $counter++; 0; });
is $counter, 1;

is length ($tag -> id), 40;
my $lookup_tag = Git::Raw::Tag -> lookup($repo, $tag -> id);
isa_ok $lookup_tag, 'Git::Raw::Tag';
is $lookup_tag -> id, $tag -> id;

is $tag -> tagger -> name, $name;
is $tag -> tagger -> email, $email;
is $tag -> tagger -> time, $time;
is $tag -> tagger -> offset, $off;

my $target = $tag -> target;

is $target -> summary, "third commit";

is $target -> author -> name, $name;
is $target -> author -> email, $email;

my @tags = $repo -> tags;

isa_ok $tags[0], 'Git::Raw::Tag';

is $tags[0] -> name, $tag_name;
is $tags[0] -> message, $tag_msg;
is $tags[1], undef;

ok (!eval { $repo -> tags('invalid') });

@tags = $repo -> tags('all');
is scalar(@tags), 1;

@tags = $repo -> tags('lightweight');
is scalar(@tags), 0;

@tags = $repo -> tags(undef);
is scalar(@tags), 1;

$tags[0] -> delete;

Git::Raw::Reference -> create("refs/tags/lightweight-tag", $repo, $commit);

@tags = $repo -> tags;

my $lw_tag = $tags[0];
isa_ok $lw_tag, 'Git::Raw::Reference';
is $lw_tag -> is_tag, 1;
is $lw_tag -> is_branch, 0;
$lw_tag = undef;

@tags = $repo -> tags('lightweight');
is scalar(@tags), 1;

@tags = $repo -> tags('annotated');
is scalar(@tags), 0;

Git::Raw::Reference -> lookup("refs/tags/lightweight-tag", $repo) -> delete();

is $repo -> tags, 0;

done_testing;