forked from acme/git-pureperl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple.t
128 lines (112 loc) · 4.39 KB
/
simple.t
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!perl
use strict;
use warnings;
use Test::More;
use Git::PurePerl;
use Path::Class;
my $checkout_directory = dir('t/checkout');
foreach my $directory (qw(test-project test-project-packs test-project-packs2))
{
my $git = Git::PurePerl->new( directory => $directory );
like( $git->master_sha1, qr/^[a-z0-9]{40}$/ );
my $commit = $git->master;
is( $commit->kind, 'commit' );
is( $commit->size, 256 );
like( $commit->sha1, qr/^[a-z0-9]{40}$/ );
is( $commit->tree_sha1, '37b4fcd62571f07408e830f455268891f95cecf5' );
like( $commit->parent_sha1, qr/^[a-z0-9]{40}$/ );
isa_ok( $commit->author, 'Git::PurePerl::Actor' );
isa_ok( $commit->committer, 'Git::PurePerl::Actor' );
is( $commit->author->name, 'Your Name Comes Here' );
is( $commit->committer->name, 'Your Name Comes Here' );
isa_ok( $commit->authored_time, 'DateTime' );
is( $commit->authored_time->month, 11 );
is( $commit->comment, 'add again' );
my $tree = $commit->tree;
is( $tree->kind, 'tree' );
is( $tree->size, 36 );
my @directory_entries = $tree->directory_entries;
is( @directory_entries, 1 );
my $directory_entry = $directory_entries[0];
is( $directory_entry->mode, '100644' );
is( $directory_entry->filename, 'file.txt' );
is( $directory_entry->sha1, '513feba2e53ebbd2532419ded848ba19de88ba00' );
my $blob = $directory_entry->object;
is( $blob->kind, 'blob' );
is( $blob->size, 32 );
is( $blob->content, 'hello world!
hello world, again
'
);
$commit = $commit->parent;
is( $commit->kind, 'commit' );
is( $commit->size, 259 );
like( $commit->sha1, qr/^[a-z0-9]{40}$/ );
is( $commit->tree_sha1, 'd0492b368b66bdabf2ac1fd8c92b39d3db916e59' );
like( $commit->parent_sha1, qr/^[a-z0-9]{40}$/ );
is( $commit->author->email, '[email protected]' );
is( $commit->committer->email, '[email protected]' );
is( $commit->comment, 'add emphasis' );
$tree = $commit->tree;
is( $tree->kind, 'tree' );
is( $tree->size, 36 );
@directory_entries = $tree->directory_entries;
is( @directory_entries, 1 );
$directory_entry = $directory_entries[0];
is( $directory_entry->mode, '100644' );
is( $directory_entry->filename, 'file.txt' );
is( $directory_entry->sha1, 'a0423896973644771497bdc03eb99d5281615b51' );
$blob = $directory_entry->object;
is( $blob->kind, 'blob' );
is( $blob->size, 13 );
is( $blob->content, 'hello world!
'
);
$commit = $commit->parent;
is( $commit->kind, 'commit' );
is( $commit->size, 213 );
like( $commit->sha1, qr/^[a-z0-9]{40}$/ );
is( $commit->tree_sha1, '92b8b694ffb1675e5975148e1121810081dbdffe' );
is( $commit->parent_sha1, undef );
is( $commit->parent, undef );
is( $commit->author->name, 'Your Name Comes Here' );
is( $commit->committer->name, 'Your Name Comes Here' );
is( $commit->comment, 'initial commit' );
$tree = $commit->tree;
is( $tree->kind, 'tree' );
is( $tree->size, 36 );
@directory_entries = $tree->directory_entries;
is( @directory_entries, 1 );
$directory_entry = $directory_entries[0];
is( $directory_entry->mode, '100644' );
is( $directory_entry->filename, 'file.txt' );
is( $directory_entry->sha1, '3b18e512dba79e4c8300dd08aeb37f8e728b8dad' );
$blob = $directory_entry->object;
is( $blob->kind, 'blob' );
is( $blob->size, 12 );
is( $blob->content, 'hello world
'
);
is( $git->all_sha1s->all, 9 );
is( $git->all_objects->all, 9 );
is( $git->config->get(key => 'user.name'), 'Your Name Comes Here' );
$checkout_directory->rmtree;
$checkout_directory->mkpath;
$git->checkout($checkout_directory);
is_deeply( [ $checkout_directory->as_foreign('Unix')->children ],
['t/checkout/file.txt'], 'checkout has one file' );
is( file('t/checkout/file.txt')->slurp, 'hello world!
hello world, again
', 'checkout has latest content'
);
is_deeply( [ $git->ref_names ], ['refs/heads/master'], 'have ref names' );
isa_ok( ( $git->refs )[0], 'Git::PurePerl::Object::Commit', 'have refs' );
ok( $git->refs_sha1, 'have refs_sha1' );
ok( $git->ref_sha1('refs/heads/master'), 'have ref_sha1 for master' );
isa_ok(
$git->ref('refs/heads/master'),
'Git::PurePerl::Object::Commit',
'have ref master'
);
}
done_testing;