Commit | Line | Data |
a8a8f8f9 |
1 | use strict; |
2 | use warnings; |
3 | use FindBin qw/$Bin/; |
5156786b |
4 | use Test::More; |
56908878 |
5 | use Test::Exception; |
a8a8f8f9 |
6 | use Data::Dumper; |
7 | |
50394a3e |
8 | use Path::Class; |
44a9ed75 |
9 | use Gitalist::Git::Repository; |
82bc0f05 |
10 | my $repository = Gitalist::Git::Repository->new( |
b5b638f7 |
11 | dir("$Bin/lib/repositories/repo1"), |
50394a3e |
12 | ); |
13 | |
467fa7d9 |
14 | BEGIN { |
15 | use_ok 'Gitalist::Git::Object::Tree'; |
16 | use_ok 'Gitalist::Git::Object::Blob'; |
17 | use_ok 'Gitalist::Git::Object::Commit'; |
18 | use_ok 'Gitalist::Git::Object::Tag'; |
19 | } |
a8a8f8f9 |
20 | |
467fa7d9 |
21 | my $object = Gitalist::Git::Object::Tree->new( |
82bc0f05 |
22 | repository => $repository, |
a8a8f8f9 |
23 | sha1 => '729a7c3f6ba5453b42d16a43692205f67fb23bc1', |
24 | type => 'tree', |
25 | file => 'dir1', |
26 | mode => 16384, |
27 | ); |
467fa7d9 |
28 | isa_ok($object, 'Gitalist::Git::Object::Tree', 'tree object'); |
50394a3e |
29 | is($object->sha1,'729a7c3f6ba5453b42d16a43692205f67fb23bc1', 'sha1 is correct'); |
30 | is($object->type, 'tree', 'type is correct'); |
31 | is($object->file, 'dir1', 'file is correct'); |
a8a8f8f9 |
32 | is($object->mode, 16384, 'mode is correct'); |
65ffc9fb |
33 | is($object->modestr, 'drwxr-xr-x', "modestr is correct" ); |
483b98b7 |
34 | is($object->size, 33, "size is correct"); |
a8a8f8f9 |
35 | |
54368e9d |
36 | # Create object from sha1. |
467fa7d9 |
37 | my $obj2 = Gitalist::Git::Object::Blob->new( |
82bc0f05 |
38 | repository => $repository, |
50394a3e |
39 | sha1 => '5716ca5987cbf97d6bb54920bea6adde242d87e6', |
50394a3e |
40 | ); |
467fa7d9 |
41 | isa_ok($obj2, 'Gitalist::Git::Object::Blob', 'blob object'); |
50394a3e |
42 | is($obj2->sha1,'5716ca5987cbf97d6bb54920bea6adde242d87e6', 'sha1 is correct'); |
43 | is($obj2->type, 'blob', 'type is correct'); |
54368e9d |
44 | is($obj2->mode, 0, 'mode is correct'); |
65ffc9fb |
45 | is($obj2->modestr, '----------', "modestr is correct" ); |
56908878 |
46 | is($obj2->content, "bar\n", 'obj2 contents is correct'); |
483b98b7 |
47 | is($obj2->size, 4, "size is correct"); |
56908878 |
48 | dies_ok { |
49 | print $obj2->tree_sha1; |
50 | } 'tree_sha1 on a blob is an exception'; |
51 | dies_ok { |
52 | print $obj2->comment; |
53 | } 'comment is an empty string'; |
85762693 |
54 | |
467fa7d9 |
55 | my $commit_obj = Gitalist::Git::Object::Commit->new( |
82bc0f05 |
56 | repository => $repository, |
85762693 |
57 | sha1 => '3f7567c7bdf7e7ebf410926493b92d398333116e', |
58 | ); |
467fa7d9 |
59 | isa_ok($commit_obj, 'Gitalist::Git::Object::Commit', "commit object"); |
85762693 |
60 | my ($tree, $patch) = $commit_obj->diff( |
61 | parent => undef, |
8254b171 |
62 | filename => undef, |
85762693 |
63 | patch => 1, |
64 | ); |
65 | $patch = $patch->[0]; |
66 | is($patch->{head}, 'diff --git a/file1 b/file1', 'patch->{head} is correct'); |
67 | is($patch->{a}, 'a/file1', 'patch->{a} is correct'); |
68 | is($patch->{b}, 'b/file1', 'patch->{b} is correct'); |
69 | is($patch->{file}, 'file1', 'patch->{file} is correct'); |
70 | is($patch->{mode}, '100644', 'patch->{mode} is correct'); |
71 | is($patch->{src}, '257cc5642cb1a054f08cc83f2d943e56fd3ebe99', 'patch->{src} is correct'); |
72 | is($patch->{index}, 'index 257cc5642cb1a054f08cc83f2d943e56fd3ebe99..5716ca5987cbf97d6bb54920bea6adde242d87e6 100644', 'patch->{index} is correct'); |
73 | is($patch->{diff}, '--- a/file1 |
74 | +++ b/file1 |
75 | @@ -1 +1 @@ |
76 | -foo |
77 | +bar |
78 | ', 'patch->{diff} is correct'); |
79 | is($patch->{dst}, '5716ca5987cbf97d6bb54920bea6adde242d87e6', 'patch->{dst} is correct'); |
377bf360 |
80 | |
5156786b |
81 | ok(index(do { local $/; my $fh = $commit_obj->get_patch; <$fh> }, |
82 | 'From 3f7567c7bdf7e7ebf410926493b92d398333116e Mon Sep 17 00:00:00 2001 |
377bf360 |
83 | From: Florian Ragwitz <rafl@debian.org> |
84 | Date: Tue, 6 Mar 2007 20:39:45 +0100 |
85 | Subject: [PATCH] bar |
86 | |
f45b8ead |
87 | --- |
88 | file1 | 2 +- |
89 | 1 files changed, 1 insertions(+), 1 deletions(-) |
377bf360 |
90 | |
91 | diff --git a/file1 b/file1 |
92 | index 257cc56..5716ca5 100644 |
93 | --- a/file1 |
94 | +++ b/file1 |
95 | @@ -1 +1 @@ |
96 | -foo |
97 | +bar |
e75df318 |
98 | --') == 0, 'commit_obj->get_patch can return a patch'); |
f707d264 |
99 | |
0af41853 |
100 | # Note - 2 patches = 3 parts due to where we split. |
101 | { |
102 | my @bits = split /Subject: \[PATC/, do { local $/; my $fh = $commit_obj->get_patch(undef, 3); <$fh> }; |
103 | is(scalar(@bits), 3, |
104 | 'commit_obj->get_patch can return a patchset'); |
105 | } |
5156786b |
106 | done_testing; |
107 | |