Now heads show up in the shortlog and the current head is marked up in the heads...
[catagits/Gitalist.git] / t / model_Git.t
1 use strict;
2 use warnings;
3 use FindBin qw/$Bin/;
4 use Test::More qw/no_plan/;
5
6 BEGIN { use_ok 'Gitalist::Model::Git' }
7
8 my $c = bless {}, 'Gitalist';
9 my $m = Gitalist::Model::Git->new($c, { repo_dir => "$Bin/lib/repositories" });
10 isa_ok($m, 'Gitalist::Model::Git');
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');
15 ok( $m->is_git_repo( $repoBare ), 'is_git_repo true for bare git repo' );
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');
19 #ok( $m->is_git_repo( $repoWorking ), 'is_git_repo true for git repo in working copy' );
20
21 # 'empty.git' is an empty directory in the repository dir
22 my $repoEmpty = Path::Class::Dir->new('t/lib/repositories/empty.git');
23 ok( ! $m->is_git_repo( $repoEmpty ), 'is_git_repo is false for empty dir' );
24
25 my $projectList = $m->list_projects('t/lib/repositories');
26 ok( scalar @{$projectList} == 2, 'list_projects returns an array with the correct number of members' );
27 is( $projectList->[0]->{name}, 'bare.git', 'list_projects has correct name for "bare.git" repo' );
28 #ok( $projectList->[1]->{name} eq 'working/.git', 'list_projects has correct name for "working" repo' );
29
30
31 # Liberally borrowed from rafl's gitweb
32 my $repo = 'repo1';
33
34 like($m->head_hash('HEAD', $repo), qr/^([0-9a-fA-F]{40})$/, 'head_hash');
35
36 {
37     my @tree = $m->list_tree('3bc0634310b9c62222bb0e724c11ffdfb297b4ac', $repo);
38
39     is(scalar @tree, 1);
40     is_deeply($tree[0], {
41             mode => oct 100644,
42             type => 'blob',
43             object => '257cc5642cb1a054f08cc83f2d943e56fd3ebe99',
44             file => 'file1'
45     });
46
47     is($m->get_object_mode_string($tree[0]), '-rw-r--r--');
48 }
49
50 is($m->get_object_type('729a7c3f6ba5453b42d16a43692205f67fb23bc1', $repo), 'tree');
51 is($m->get_object_type('257cc5642cb1a054f08cc83f2d943e56fd3ebe99', $repo), 'blob');
52 is($m->get_object_type('5716ca5987cbf97d6bb54920bea6adde242d87e6', $repo), 'blob');
53
54 is($m->cat_file('257cc5642cb1a054f08cc83f2d943e56fd3ebe99', $repo), "foo\n");
55 is($m->cat_file('5716ca5987cbf97d6bb54920bea6adde242d87e6', $repo), "bar\n");
56
57 is($m->diff('3bc0634310b9c62222bb0e724c11ffdfb297b4ac', '3f7567c7bdf7e7ebf410926493b92d398333116e', $repo), <<EOD);
58 diff --git a/file1 b/file1
59 index 257cc56..5716ca5 100644
60 --- a/file1
61 +++ b/file1
62 @@ -1 +1 @@
63 -foo
64 +bar
65 EOD