3 my $env = "$FindBin::Bin/../script/env";
16 use Gitalist::Git::Repository;
17 my $repository = Gitalist::Git::Repository->new(
18 dir("$Bin/lib/repositories/repo1"),
22 use_ok 'Gitalist::Git::Object::Tree';
23 use_ok 'Gitalist::Git::Object::Blob';
24 use_ok 'Gitalist::Git::Object::Commit';
25 use_ok 'Gitalist::Git::Object::Tag';
28 my $object = Gitalist::Git::Object::Tree->new(
29 repository => $repository,
30 sha1 => '729a7c3f6ba5453b42d16a43692205f67fb23bc1',
35 isa_ok($object, 'Gitalist::Git::Object::Tree', 'tree object');
36 is($object->sha1,'729a7c3f6ba5453b42d16a43692205f67fb23bc1', 'sha1 is correct');
37 is($object->type, 'tree', 'type is correct');
38 is($object->file, 'dir1', 'file is correct');
39 is($object->mode, 16384, 'mode is correct');
40 is($object->modestr, 'drwxr-xr-x', "modestr is correct" );
41 is($object->size, 33, "size is correct");
42 is($object,'729a7c3f6ba5453b42d16a43692205f67fb23bc1', 'stringifies correctly');
44 # Create object from sha1.
45 my $obj2 = Gitalist::Git::Object::Blob->new(
46 repository => $repository,
47 sha1 => '5716ca5987cbf97d6bb54920bea6adde242d87e6',
49 isa_ok($obj2, 'Gitalist::Git::Object::Blob', 'blob object');
50 is($obj2->sha1,'5716ca5987cbf97d6bb54920bea6adde242d87e6', 'sha1 is correct');
51 is($obj2->type, 'blob', 'type is correct');
52 is($obj2->mode, 0, 'mode is correct');
53 is($obj2->modestr, '----------', "modestr is correct" );
54 is($obj2->content, "bar\n", 'obj2 contents is correct');
55 is($obj2->size, 4, "size is correct");
57 print $obj2->tree_sha1;
58 } 'tree_sha1 on a blob is an exception';
61 } 'comment is an empty string';
63 my $commit_obj = Gitalist::Git::Object::Commit->new(
64 repository => $repository,
65 sha1 => '3f7567c7bdf7e7ebf410926493b92d398333116e',
67 isa_ok($commit_obj, 'Gitalist::Git::Object::Commit', "commit object");
68 isa_ok($commit_obj->tree->[0], 'Gitalist::Git::Object::Tree');
69 my ($tree, $patch) = $commit_obj->diff(
73 is($patch->{head}, 'diff --git a/file1 b/file1', 'patch->{head} is correct');
74 is($patch->{a}, 'a/file1', 'patch->{a} is correct');
75 is($patch->{b}, 'b/file1', 'patch->{b} is correct');
76 is($patch->{file}, 'file1', 'patch->{file} is correct');
77 is($patch->{mode}, '100644', 'patch->{mode} is correct');
78 is($patch->{src}, '257cc5642cb1a054f08cc83f2d943e56fd3ebe99', 'patch->{src} is correct');
79 is($patch->{index}, 'index 257cc5642cb1a054f08cc83f2d943e56fd3ebe99..5716ca5987cbf97d6bb54920bea6adde242d87e6 100644', 'patch->{index} is correct');
80 is($patch->{diff}, '--- a/file1
85 ', 'patch->{diff} is correct');
86 is($patch->{dst}, '5716ca5987cbf97d6bb54920bea6adde242d87e6', 'patch->{dst} is correct');
89 my $contents = do { local $/; my $fh = $commit_obj->get_patch; <$fh> };
91 'From 3f7567c7bdf7e7ebf410926493b92d398333116e Mon Sep 17 00:00:00 2001
92 From: Florian Ragwitz <rafl@debian.org>
93 Date: Tue, 6 Mar 2007 20:39:45 +0100
98 1 files changed, 1 insertions(+), 1 deletions(-)
100 diff --git a/file1 b/file1
101 index 257cc56..5716ca5 100644
107 --') == 0, 'commit_obj->get_patch can return a patch')
108 or warn("Got instead: $contents");
111 # Note - 2 patches = 3 parts due to where we split.
113 my $contents = do { local $/; my $fh = $commit_obj->get_patch(undef, 3); <$fh> };
114 my @bits = split /Subject: \[PATC/, $contents;
116 'commit_obj->get_patch can return a patchset')
117 or warn("Contents was $contents");