Commit | Line | Data |
a8a8f8f9 |
1 | use strict; |
2 | use warnings; |
3 | use FindBin qw/$Bin/; |
4 | use Test::More qw/no_plan/; |
56908878 |
5 | use Test::Exception; |
a8a8f8f9 |
6 | use Data::Dumper; |
7 | |
50394a3e |
8 | use Path::Class; |
9 | use Gitalist::Git::Project; |
10 | my $project = Gitalist::Git::Project->new( |
b5b638f7 |
11 | dir("$Bin/lib/repositories/repo1"), |
50394a3e |
12 | ); |
13 | |
a8a8f8f9 |
14 | BEGIN { use_ok 'Gitalist::Git::Object' } |
15 | |
16 | my $object = Gitalist::Git::Object->new( |
50394a3e |
17 | project => $project, |
a8a8f8f9 |
18 | sha1 => '729a7c3f6ba5453b42d16a43692205f67fb23bc1', |
19 | type => 'tree', |
20 | file => 'dir1', |
21 | mode => 16384, |
22 | ); |
23 | isa_ok($object, 'Gitalist::Git::Object'); |
50394a3e |
24 | is($object->sha1,'729a7c3f6ba5453b42d16a43692205f67fb23bc1', 'sha1 is correct'); |
25 | is($object->type, 'tree', 'type is correct'); |
26 | is($object->file, 'dir1', 'file is correct'); |
a8a8f8f9 |
27 | is($object->mode, 16384, 'mode is correct'); |
28 | is($object->modestr, 'd---------', "modestr is correct" ); |
483b98b7 |
29 | is($object->size, 33, "size is correct"); |
a8a8f8f9 |
30 | |
54368e9d |
31 | # Create object from sha1. |
50394a3e |
32 | my $obj2 = Gitalist::Git::Object->new( |
33 | project => $project, |
34 | sha1 => '5716ca5987cbf97d6bb54920bea6adde242d87e6', |
50394a3e |
35 | ); |
36 | isa_ok($obj2, 'Gitalist::Git::Object'); |
37 | is($obj2->sha1,'5716ca5987cbf97d6bb54920bea6adde242d87e6', 'sha1 is correct'); |
38 | is($obj2->type, 'blob', 'type is correct'); |
54368e9d |
39 | is($obj2->mode, 0, 'mode is correct'); |
40 | is($obj2->modestr, '?---------', "modestr is correct" ); |
56908878 |
41 | is($obj2->content, "bar\n", 'obj2 contents is correct'); |
483b98b7 |
42 | is($obj2->size, 4, "size is correct"); |
56908878 |
43 | dies_ok { |
44 | print $obj2->tree_sha1; |
45 | } 'tree_sha1 on a blob is an exception'; |
46 | dies_ok { |
47 | print $obj2->comment; |
48 | } 'comment is an empty string'; |
85762693 |
49 | |
50 | my $commit_obj = Gitalist::Git::Object->new( |
51 | project => $project, |
52 | sha1 => '3f7567c7bdf7e7ebf410926493b92d398333116e', |
53 | ); |
54 | isa_ok($commit_obj, 'Gitalist::Git::Object', "commit object type correct"); |
55 | my ($tree, $patch) = $commit_obj->diff( |
56 | parent => undef, |
57 | file => undef, |
58 | patch => 1, |
59 | ); |
60 | $patch = $patch->[0]; |
61 | is($patch->{head}, 'diff --git a/file1 b/file1', 'patch->{head} is correct'); |
62 | is($patch->{a}, 'a/file1', 'patch->{a} is correct'); |
63 | is($patch->{b}, 'b/file1', 'patch->{b} is correct'); |
64 | is($patch->{file}, 'file1', 'patch->{file} is correct'); |
65 | is($patch->{mode}, '100644', 'patch->{mode} is correct'); |
66 | is($patch->{src}, '257cc5642cb1a054f08cc83f2d943e56fd3ebe99', 'patch->{src} is correct'); |
67 | is($patch->{index}, 'index 257cc5642cb1a054f08cc83f2d943e56fd3ebe99..5716ca5987cbf97d6bb54920bea6adde242d87e6 100644', 'patch->{index} is correct'); |
68 | is($patch->{diff}, '--- a/file1 |
69 | +++ b/file1 |
70 | @@ -1 +1 @@ |
71 | -foo |
72 | +bar |
73 | ', 'patch->{diff} is correct'); |
74 | is($patch->{dst}, '5716ca5987cbf97d6bb54920bea6adde242d87e6', 'patch->{dst} is correct'); |