Integrated repo and further tests from rafl's catalysed gitweb.
[catagits/Gitalist.git] / t / model_Git.t
CommitLineData
4805c465 1use strict;
2use warnings;
6dca83ef 3use FindBin qw/$Bin/;
4805c465 4use Test::More qw/no_plan/;
5
6BEGIN { use_ok 'Gitalist::Model::Git' }
7
6dca83ef 8my $c = bless {}, 'Gitalist';
a88a2b6d 9my $m = Gitalist::Model::Git->new($c, { repo_dir => "$Bin/lib/repositories" });
10isa_ok($m, 'Gitalist::Model::Git');
4805c465 11
12# 'bare.git' is a bare git repository in the repository dir
13use Path::Class;
14my $repoBare = Path::Class::Dir->new('t/lib/repositories/bare.git');
a88a2b6d 15ok( $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
18my $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
22my $repoEmpty = Path::Class::Dir->new('t/lib/repositories/empty.git');
a88a2b6d 23ok( ! $m->is_git_repo( $repoEmpty ), 'is_git_repo is false for empty dir' );
4805c465 24
a88a2b6d 25my $projectList = $m->list_projects;
26ok( scalar @{$projectList} == 2, 'list_projects returns an array with the correct number of members' );
4805c465 27ok( $projectList->[0]->{name} eq '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
32my $repo = 'repo1';
33
34like($m->get_head_hash($repo), qr/^([0-9a-fA-F]{40})$/, 'get_head_hash');
35
36{
37 my @tree = $m->list_tree($repo, '3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
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
50is($m->get_object_type($repo, '729a7c3f6ba5453b42d16a43692205f67fb23bc1'), 'tree');
51is($m->get_object_type($repo, '257cc5642cb1a054f08cc83f2d943e56fd3ebe99'), 'blob');
52is($m->get_object_type($repo, '5716ca5987cbf97d6bb54920bea6adde242d87e6'), 'blob');
53
54is($m->cat_file($repo, '257cc5642cb1a054f08cc83f2d943e56fd3ebe99'), "foo\n");
55is($m->cat_file($repo, '5716ca5987cbf97d6bb54920bea6adde242d87e6'), "bar\n");
56
57is($m->diff($repo, '3bc0634310b9c62222bb0e724c11ffdfb297b4ac', '3f7567c7bdf7e7ebf410926493b92d398333116e'), <<EOD);
58diff --git a/file1 b/file1
59index 257cc56..5716ca5 100644
60--- a/file1
61+++ b/file1
62@@ -1 +1 @@
63-foo
64+bar
65EOD
66
67use Data::Dumper;
68warn( Dumper( $m->list_revs($repo) ));