Commit | Line | Data |
cce03a80 |
1 | use FindBin qw/$Bin/; |
df629266 |
2 | BEGIN { |
0556ab26 |
3 | my $env = "$FindBin::Bin/../script/env"; |
df629266 |
4 | if (-r $env) { |
5 | do $env or die $@; |
6 | } |
7 | } |
8 | |
a8a8f8f9 |
9 | use strict; |
10 | use warnings; |
5156786b |
11 | use Test::More; |
56908878 |
12 | use Test::Exception; |
a8a8f8f9 |
13 | use Data::Dumper; |
14 | |
50394a3e |
15 | use Path::Class; |
44a9ed75 |
16 | use Gitalist::Git::Repository; |
82bc0f05 |
17 | my $repository = Gitalist::Git::Repository->new( |
b5b638f7 |
18 | dir("$Bin/lib/repositories/repo1"), |
50394a3e |
19 | ); |
20 | |
467fa7d9 |
21 | BEGIN { |
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'; |
26 | } |
a8a8f8f9 |
27 | |
467fa7d9 |
28 | my $object = Gitalist::Git::Object::Tree->new( |
82bc0f05 |
29 | repository => $repository, |
a8a8f8f9 |
30 | sha1 => '729a7c3f6ba5453b42d16a43692205f67fb23bc1', |
31 | type => 'tree', |
32 | file => 'dir1', |
33 | mode => 16384, |
34 | ); |
467fa7d9 |
35 | isa_ok($object, 'Gitalist::Git::Object::Tree', 'tree object'); |
50394a3e |
36 | is($object->sha1,'729a7c3f6ba5453b42d16a43692205f67fb23bc1', 'sha1 is correct'); |
37 | is($object->type, 'tree', 'type is correct'); |
38 | is($object->file, 'dir1', 'file is correct'); |
a8a8f8f9 |
39 | is($object->mode, 16384, 'mode is correct'); |
65ffc9fb |
40 | is($object->modestr, 'drwxr-xr-x', "modestr is correct" ); |
483b98b7 |
41 | is($object->size, 33, "size is correct"); |
acd0be23 |
42 | is($object,'729a7c3f6ba5453b42d16a43692205f67fb23bc1', 'stringifies correctly'); |
a8a8f8f9 |
43 | |
1aae440e |
44 | is_deeply $object->pack, { |
45 | __CLASS__ |
46 | => 'Gitalist::Git::Object::Tree', |
47 | file => 'dir1', |
48 | mode => 16384, |
49 | modestr |
50 | => 'drwxr-xr-x', |
51 | repository |
52 | => { |
53 | __CLASS__ => 'Gitalist::Git::Repository', |
54 | description => 'some test repository', |
55 | is_bare => 1, |
56 | last_change => '2009-11-12T19:00:34Z', |
57 | name => 'repo1', |
58 | owner => 'Dan' |
59 | }, |
60 | sha1 => '729a7c3f6ba5453b42d16a43692205f67fb23bc1', |
61 | size => 33, |
62 | type => 'tree' |
63 | }, 'Serialized tree correctly'; |
64 | |
54368e9d |
65 | # Create object from sha1. |
467fa7d9 |
66 | my $obj2 = Gitalist::Git::Object::Blob->new( |
82bc0f05 |
67 | repository => $repository, |
50394a3e |
68 | sha1 => '5716ca5987cbf97d6bb54920bea6adde242d87e6', |
50394a3e |
69 | ); |
467fa7d9 |
70 | isa_ok($obj2, 'Gitalist::Git::Object::Blob', 'blob object'); |
50394a3e |
71 | is($obj2->sha1,'5716ca5987cbf97d6bb54920bea6adde242d87e6', 'sha1 is correct'); |
72 | is($obj2->type, 'blob', 'type is correct'); |
54368e9d |
73 | is($obj2->mode, 0, 'mode is correct'); |
65ffc9fb |
74 | is($obj2->modestr, '----------', "modestr is correct" ); |
56908878 |
75 | is($obj2->content, "bar\n", 'obj2 contents is correct'); |
483b98b7 |
76 | is($obj2->size, 4, "size is correct"); |
56908878 |
77 | dies_ok { |
78 | print $obj2->tree_sha1; |
79 | } 'tree_sha1 on a blob is an exception'; |
80 | dies_ok { |
81 | print $obj2->comment; |
82 | } 'comment is an empty string'; |
85762693 |
83 | |
1aae440e |
84 | is_deeply $obj2->pack, { |
85 | __CLASS__ |
86 | => 'Gitalist::Git::Object::Blob', |
87 | mode => 0, |
88 | modestr |
89 | => '----------', |
90 | repository |
91 | => { |
92 | __CLASS__ => 'Gitalist::Git::Repository', |
93 | description => 'some test repository', |
94 | is_bare => 1, |
95 | last_change => '2009-11-12T19:00:34Z', |
96 | name => 'repo1', |
97 | owner => 'Dan' |
98 | }, |
99 | sha1 => '5716ca5987cbf97d6bb54920bea6adde242d87e6', |
100 | size => 4, |
101 | type => 'blob' |
102 | }, 'Serialized blob correctly'; |
103 | |
467fa7d9 |
104 | my $commit_obj = Gitalist::Git::Object::Commit->new( |
82bc0f05 |
105 | repository => $repository, |
85762693 |
106 | sha1 => '3f7567c7bdf7e7ebf410926493b92d398333116e', |
107 | ); |
467fa7d9 |
108 | isa_ok($commit_obj, 'Gitalist::Git::Object::Commit', "commit object"); |
220ff256 |
109 | isa_ok($commit_obj->tree->[0], 'Gitalist::Git::Object::Tree'); |
1aae440e |
110 | |
111 | is_deeply $commit_obj->pack, { |
112 | __CLASS__ |
113 | => 'Gitalist::Git::Object::Commit', |
114 | mode => 0, |
115 | modestr |
116 | => '----------', |
117 | repository |
118 | => { |
119 | __CLASS__ => 'Gitalist::Git::Repository', |
120 | description => 'some test repository', |
121 | is_bare => 1, |
122 | last_change => '2009-11-12T19:00:34Z', |
123 | name => 'repo1', |
124 | owner => 'Dan' |
125 | }, |
126 | sha1 => '3f7567c7bdf7e7ebf410926493b92d398333116e', |
127 | size => 218, |
128 | tree => [ { |
129 | __CLASS__ |
130 | => 'Gitalist::Git::Object::Tree', |
131 | mode => 0, |
132 | modestr |
133 | => '----------', |
134 | repository |
135 | => { |
136 | __CLASS__ => 'Gitalist::Git::Repository', |
137 | description => 'some test repository', |
138 | is_bare => 1, |
139 | last_change => '2009-11-12T19:00:34Z', |
140 | name => 'repo1', |
141 | owner => 'Dan' |
142 | }, |
143 | sha1 => '9062594aebb5df0de7fb92413f17a9eced196c22', |
144 | size => 33, |
145 | type => 'tree' |
146 | } ], |
147 | type => 'commit' |
148 | }, 'Serialized commit correctly'; |
149 | |
85762693 |
150 | my ($tree, $patch) = $commit_obj->diff( |
85762693 |
151 | patch => 1, |
152 | ); |
153 | $patch = $patch->[0]; |
154 | is($patch->{head}, 'diff --git a/file1 b/file1', 'patch->{head} is correct'); |
155 | is($patch->{a}, 'a/file1', 'patch->{a} is correct'); |
156 | is($patch->{b}, 'b/file1', 'patch->{b} is correct'); |
157 | is($patch->{file}, 'file1', 'patch->{file} is correct'); |
158 | is($patch->{mode}, '100644', 'patch->{mode} is correct'); |
159 | is($patch->{src}, '257cc5642cb1a054f08cc83f2d943e56fd3ebe99', 'patch->{src} is correct'); |
160 | is($patch->{index}, 'index 257cc5642cb1a054f08cc83f2d943e56fd3ebe99..5716ca5987cbf97d6bb54920bea6adde242d87e6 100644', 'patch->{index} is correct'); |
161 | is($patch->{diff}, '--- a/file1 |
162 | +++ b/file1 |
163 | @@ -1 +1 @@ |
164 | -foo |
165 | +bar |
166 | ', 'patch->{diff} is correct'); |
167 | is($patch->{dst}, '5716ca5987cbf97d6bb54920bea6adde242d87e6', 'patch->{dst} is correct'); |
377bf360 |
168 | |
e4f50c24 |
169 | { |
170 | my $contents = do { local $/; my $fh = $commit_obj->get_patch; <$fh> }; |
171 | ok(index($contents, |
5156786b |
172 | 'From 3f7567c7bdf7e7ebf410926493b92d398333116e Mon Sep 17 00:00:00 2001 |
377bf360 |
173 | From: Florian Ragwitz <rafl@debian.org> |
174 | Date: Tue, 6 Mar 2007 20:39:45 +0100 |
175 | Subject: [PATCH] bar |
176 | |
f45b8ead |
177 | --- |
178 | file1 | 2 +- |
179 | 1 files changed, 1 insertions(+), 1 deletions(-) |
377bf360 |
180 | |
181 | diff --git a/file1 b/file1 |
182 | index 257cc56..5716ca5 100644 |
183 | --- a/file1 |
184 | +++ b/file1 |
185 | @@ -1 +1 @@ |
186 | -foo |
187 | +bar |
e4f50c24 |
188 | --') == 0, 'commit_obj->get_patch can return a patch') |
189 | or warn("Got instead: $contents"); |
190 | } |
f707d264 |
191 | |
0af41853 |
192 | # Note - 2 patches = 3 parts due to where we split. |
193 | { |
e4f50c24 |
194 | my $contents = do { local $/; my $fh = $commit_obj->get_patch(undef, 3); <$fh> }; |
195 | my @bits = split /Subject: \[PATC/, $contents; |
0af41853 |
196 | is(scalar(@bits), 3, |
e4f50c24 |
197 | 'commit_obj->get_patch can return a patchset') |
198 | or warn("Contents was $contents"); |
0af41853 |
199 | } |
5156786b |
200 | done_testing; |
201 | |