Commit | Line | Data |
4805c465 |
1 | use strict; |
2 | use warnings; |
6dca83ef |
3 | use FindBin qw/$Bin/; |
43ca94af |
4 | use Test::More; |
4805c465 |
5 | |
6 | BEGIN { use_ok 'Gitalist::Model::Git' } |
7 | |
da5fab33 |
8 | use Git::PurePerl; |
0caa4dd2 |
9 | my $m = Git::Repos->new({ repo_dir => "$Bin/lib/repositories" }); |
43ca94af |
10 | isa_ok($m, 'Git::Repos'); |
4805c465 |
11 | |
12 | # 'bare.git' is a bare git repository in the repository dir |
13 | use Path::Class; |
14 | my $repoBare = Path::Class::Dir->new('t/lib/repositories/bare.git'); |
a88a2b6d |
15 | ok( $m->is_git_repo( $repoBare ), 'is_git_repo true for bare git repo' ); |
4805c465 |
16 | |
17 | # 'working' is a working copy w/ git repo in the repository dir |
18 | my $repoWorking = Path::Class::Dir->new('t/lib/repositories/working'); |
a88a2b6d |
19 | #ok( $m->is_git_repo( $repoWorking ), 'is_git_repo true for git repo in working copy' ); |
4805c465 |
20 | |
21 | # 'empty.git' is an empty directory in the repository dir |
22 | my $repoEmpty = Path::Class::Dir->new('t/lib/repositories/empty.git'); |
a88a2b6d |
23 | ok( ! $m->is_git_repo( $repoEmpty ), 'is_git_repo is false for empty dir' ); |
4805c465 |
24 | |
27e05d7b |
25 | my $projectList = $m->list_projects('t/lib/repositories'); |
a88a2b6d |
26 | ok( scalar @{$projectList} == 2, 'list_projects returns an array with the correct number of members' ); |
27e05d7b |
27 | is( $projectList->[0]->{name}, 'bare.git', 'list_projects has correct name for "bare.git" repo' ); |
0e2b6322 |
28 | #ok( $projectList->[1]->{name} eq 'working/.git', 'list_projects has correct name for "working" repo' ); |
4805c465 |
29 | |
4805c465 |
30 | |
a88a2b6d |
31 | # Liberally borrowed from rafl's gitweb |
da5fab33 |
32 | $m->project('repo1'); |
33 | is($m->project, 'repo1', 'model project correct'); |
34 | my $pd = $m->project_dir($m->project); |
e983a32e |
35 | isa_ok($pd, 'Path::Class::Dir', 'model project_dir'); |
da5fab33 |
36 | is($pd, $m->repo_dir . '/' . $m->project, 'model project_dir correct'); |
37 | ok( $m->gpp(Git::PurePerl->new( gitdir => $pd, directory => $pd )), 'model gpp set ok' ); |
38 | like($m->head_hash('HEAD'), qr/^([0-9a-fA-F]{40})$/, 'head_hash'); |
a88a2b6d |
39 | |
40 | { |
da5fab33 |
41 | my @tree = $m->list_tree('3bc0634310b9c62222bb0e724c11ffdfb297b4ac'); |
89a18cae |
42 | is(scalar @tree, 1, "tree array contains one entry."); |
a88a2b6d |
43 | is_deeply($tree[0], { |
89a18cae |
44 | mode => oct 100644, |
45 | modestr => '-rw-r--r--', |
46 | type => 'blob', |
47 | object => '257cc5642cb1a054f08cc83f2d943e56fd3ebe99', |
48 | file => 'file1' |
a88a2b6d |
49 | }); |
50 | |
51 | is($m->get_object_mode_string($tree[0]), '-rw-r--r--'); |
52 | } |
53 | |
da5fab33 |
54 | is($m->get_object_type('729a7c3f6ba5453b42d16a43692205f67fb23bc1'), 'tree'); |
55 | is($m->get_object_type('257cc5642cb1a054f08cc83f2d943e56fd3ebe99'), 'blob'); |
56 | is($m->get_object_type('5716ca5987cbf97d6bb54920bea6adde242d87e6'), 'blob'); |
57 | |
58 | is($m->cat_file('257cc5642cb1a054f08cc83f2d943e56fd3ebe99'), "foo\n"); |
59 | is($m->cat_file('5716ca5987cbf97d6bb54920bea6adde242d87e6'), "bar\n"); |
60 | |
61 | |
62 | my $commit = $m->get_object('3f7567c7bdf7e7ebf410926493b92d398333116e'); |
63 | isa_ok($commit, 'Git::PurePerl::Object::Commit', "commit object type correct"); |
64 | my ($tree, $patch) = $m->diff( |
65 | commit => $commit, |
66 | parent => '', |
67 | file => '', |
68 | patch => 1, |
69 | ); |
70 | $patch = $patch->[0]; |
71 | is($patch->{head}, 'diff --git a/file1 b/file1', 'patch->{head} is correct'); |
72 | is($patch->{a}, 'a/file1', 'patch->{a} is correct'); |
73 | is($patch->{b}, 'b/file1', 'patch->{b} is correct'); |
74 | is($patch->{file}, 'file1', 'patch->{file} is correct'); |
75 | is($patch->{mode}, '100644', 'patch->{mode} is correct'); |
76 | is($patch->{src}, '257cc5642cb1a054f08cc83f2d943e56fd3ebe99', 'patch->{src} is correct'); |
77 | is($patch->{index}, 'index 257cc5642cb1a054f08cc83f2d943e56fd3ebe99..5716ca5987cbf97d6bb54920bea6adde242d87e6 100644', 'patch->{index} is correct'); |
78 | is($patch->{diff}, '--- a/file1 |
a88a2b6d |
79 | +++ b/file1 |
80 | @@ -1 +1 @@ |
81 | -foo |
82 | +bar |
da5fab33 |
83 | ', 'patch->{diff} is correct'); |
84 | is($patch->{dst}, '5716ca5987cbf97d6bb54920bea6adde242d87e6', 'patch->{dst} is correct'); |
89a18cae |
85 | |
43ca94af |
86 | done_testing; |
87 | |