3 my $env = "$FindBin::Bin/../script/env";
17 use Gitalist::Git::Repository;
18 my $repository = Gitalist::Git::Repository->new(
19 dir("$Bin/lib/repositories/repo1"),
23 use_ok 'Gitalist::Git::Object::Tree';
24 use_ok 'Gitalist::Git::Object::Blob';
25 use_ok 'Gitalist::Git::Object::Commit';
26 use_ok 'Gitalist::Git::Object::Tag';
29 my $object = Gitalist::Git::Object::Tree->new(
30 repository => $repository,
31 sha1 => '729a7c3f6ba5453b42d16a43692205f67fb23bc1',
36 isa_ok($object, 'Gitalist::Git::Object::Tree', 'tree object');
37 is($object->sha1,'729a7c3f6ba5453b42d16a43692205f67fb23bc1', 'sha1 is correct');
38 is($object->type, 'tree', 'type is correct');
39 is($object->file, 'dir1', 'file is correct');
40 is($object->mode, 16384, 'mode is correct');
41 is($object->modestr, 'drwxr-xr-x', "modestr is correct" );
42 is($object->size, 33, "size is correct");
43 is($object,'729a7c3f6ba5453b42d16a43692205f67fb23bc1', 'stringifies correctly');
45 cmp_deeply $object->pack, {
47 => 'Gitalist::Git::Object::Tree',
54 __CLASS__ => 'Gitalist::Git::Repository',
55 description => 'some test repository',
57 last_change => '2009-11-12T19:00:34Z',
59 owner => code(\&is_system_account_name),
61 sha1 => '729a7c3f6ba5453b42d16a43692205f67fb23bc1',
64 }, 'Serialized tree correctly';
66 # Create object from sha1.
67 my $obj2 = Gitalist::Git::Object::Blob->new(
68 repository => $repository,
69 sha1 => '5716ca5987cbf97d6bb54920bea6adde242d87e6',
71 isa_ok($obj2, 'Gitalist::Git::Object::Blob', 'blob object');
72 is($obj2->sha1,'5716ca5987cbf97d6bb54920bea6adde242d87e6', 'sha1 is correct');
73 is($obj2->type, 'blob', 'type is correct');
74 is($obj2->mode, 0, 'mode is correct');
75 is($obj2->modestr, '----------', "modestr is correct" );
76 is($obj2->content, "bar\n", 'obj2 contents is correct');
77 is($obj2->size, 4, "size is correct");
79 print $obj2->tree_sha1;
80 } 'tree_sha1 on a blob is an exception';
83 } 'comment is an empty string';
85 cmp_deeply $obj2->pack, {
87 => 'Gitalist::Git::Object::Blob',
93 __CLASS__ => 'Gitalist::Git::Repository',
94 description => 'some test repository',
96 last_change => '2009-11-12T19:00:34Z',
98 owner => code(\&is_system_account_name),
100 sha1 => '5716ca5987cbf97d6bb54920bea6adde242d87e6',
103 }, 'Serialized blob correctly';
105 my $commit_obj = Gitalist::Git::Object::Commit->new(
106 repository => $repository,
107 sha1 => '3f7567c7bdf7e7ebf410926493b92d398333116e',
109 isa_ok($commit_obj, 'Gitalist::Git::Object::Commit', "commit object");
110 isa_ok($commit_obj->tree->[0], 'Gitalist::Git::Object::Tree');
112 cmp_deeply $commit_obj->pack, {
114 => 'Gitalist::Git::Object::Commit',
120 __CLASS__ => 'Gitalist::Git::Repository',
121 description => 'some test repository',
123 last_change => '2009-11-12T19:00:34Z',
125 owner => code(\&is_system_account_name),
127 sha1 => '3f7567c7bdf7e7ebf410926493b92d398333116e',
131 => 'Gitalist::Git::Object::Tree',
137 __CLASS__ => 'Gitalist::Git::Repository',
138 description => 'some test repository',
140 last_change => '2009-11-12T19:00:34Z',
142 owner => code(\&is_system_account_name),
144 sha1 => '9062594aebb5df0de7fb92413f17a9eced196c22',
149 }, 'Serialized commit correctly';
151 my ($tree, $patch) = $commit_obj->diff(
154 $patch = $patch->[0];
155 is($patch->{head}, 'diff --git a/file1 b/file1', 'patch->{head} is correct');
156 is($patch->{a}, 'a/file1', 'patch->{a} is correct');
157 is($patch->{b}, 'b/file1', 'patch->{b} is correct');
158 is($patch->{file}, 'file1', 'patch->{file} is correct');
159 is($patch->{mode}, '100644', 'patch->{mode} is correct');
160 is($patch->{src}, '257cc5642cb1a054f08cc83f2d943e56fd3ebe99', 'patch->{src} is correct');
161 is($patch->{index}, 'index 257cc5642cb1a054f08cc83f2d943e56fd3ebe99..5716ca5987cbf97d6bb54920bea6adde242d87e6 100644', 'patch->{index} is correct');
162 is($patch->{diff}, '--- a/file1
167 ', 'patch->{diff} is correct');
168 is($patch->{dst}, '5716ca5987cbf97d6bb54920bea6adde242d87e6', 'patch->{dst} is correct');
171 my $contents = do { local $/; my $fh = $commit_obj->get_patch; <$fh> };
173 'From 3f7567c7bdf7e7ebf410926493b92d398333116e Mon Sep 17 00:00:00 2001
174 From: Florian Ragwitz <rafl@debian.org>
175 Date: Tue, 6 Mar 2007 20:39:45 +0100
180 1 files changed, 1 insertions(+), 1 deletions(-)
182 diff --git a/file1 b/file1
183 index 257cc56..5716ca5 100644
189 --') == 0, 'commit_obj->get_patch can return a patch')
190 or warn("Got instead: $contents");
193 # Note - 2 patches = 3 parts due to where we split.
195 my $contents = do { local $/; my $fh = $commit_obj->get_patch(undef, 3); <$fh> };
196 my @bits = split /Subject: \[PATC/, $contents;
198 'commit_obj->get_patch can return a patchset')
199 or warn("Contents was $contents");
203 sub is_system_account_name {