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