Updated model_Git.t to reflect current reality.
Zachary Stevens [Thu, 5 Nov 2009 22:08:16 +0000 (22:08 +0000)]
t/lib/repositories/repo1/objects/pack/.gitignore [new file with mode: 0644]
t/model_Git.t

diff --git a/t/lib/repositories/repo1/objects/pack/.gitignore b/t/lib/repositories/repo1/objects/pack/.gitignore
new file mode 100644 (file)
index 0000000..e69de29
index cc195c9..c87d833 100644 (file)
@@ -5,6 +5,7 @@ use Test::More;
 
 BEGIN { use_ok 'Gitalist::Model::Git' }
 
+use Git::PurePerl;
 my $m = Git::Repos->new({ repo_dir => "$Bin/lib/repositories" });
 isa_ok($m, 'Git::Repos');
 
@@ -28,12 +29,15 @@ is( $projectList->[0]->{name}, 'bare.git', 'list_projects has correct name for "
 
 
 # Liberally borrowed from rafl's gitweb
-my $repo = 'repo1';
-
-like($m->head_hash('HEAD', $repo), qr/^([0-9a-fA-F]{40})$/, 'head_hash');
+$m->project('repo1');
+is($m->project, 'repo1', 'model project correct');
+my $pd = $m->project_dir($m->project);
+is($pd, $m->repo_dir . '/' . $m->project, 'model project_dir correct');
+ok( $m->gpp(Git::PurePerl->new( gitdir => $pd, directory => $pd )), 'model gpp set ok' );
+like($m->head_hash('HEAD'), qr/^([0-9a-fA-F]{40})$/, 'head_hash');
 
 {
-    my @tree = $m->list_tree('3bc0634310b9c62222bb0e724c11ffdfb297b4ac', $repo);
+    my @tree = $m->list_tree('3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
     is(scalar @tree, 1, "tree array contains one entry.");
     is_deeply($tree[0], {
         mode => oct 100644,
@@ -46,22 +50,38 @@ like($m->head_hash('HEAD', $repo), qr/^([0-9a-fA-F]{40})$/, 'head_hash');
     is($m->get_object_mode_string($tree[0]), '-rw-r--r--');
 }
 
-is($m->get_object_type('729a7c3f6ba5453b42d16a43692205f67fb23bc1', $repo), 'tree');
-is($m->get_object_type('257cc5642cb1a054f08cc83f2d943e56fd3ebe99', $repo), 'blob');
-is($m->get_object_type('5716ca5987cbf97d6bb54920bea6adde242d87e6', $repo), 'blob');
-
-is($m->cat_file('257cc5642cb1a054f08cc83f2d943e56fd3ebe99', $repo), "foo\n");
-is($m->cat_file('5716ca5987cbf97d6bb54920bea6adde242d87e6', $repo), "bar\n");
-
-is($m->diff('3bc0634310b9c62222bb0e724c11ffdfb297b4ac', '3f7567c7bdf7e7ebf410926493b92d398333116e', $repo), <<EOD);
-diff --git a/file1 b/file1
-index 257cc56..5716ca5 100644
---- a/file1
+is($m->get_object_type('729a7c3f6ba5453b42d16a43692205f67fb23bc1'), 'tree');
+is($m->get_object_type('257cc5642cb1a054f08cc83f2d943e56fd3ebe99'), 'blob');
+is($m->get_object_type('5716ca5987cbf97d6bb54920bea6adde242d87e6'), 'blob');
+
+is($m->cat_file('257cc5642cb1a054f08cc83f2d943e56fd3ebe99'), "foo\n");
+is($m->cat_file('5716ca5987cbf97d6bb54920bea6adde242d87e6'), "bar\n");
+
+
+my $commit = $m->get_object('3f7567c7bdf7e7ebf410926493b92d398333116e');
+isa_ok($commit, 'Git::PurePerl::Object::Commit', "commit object type correct");
+my ($tree, $patch) = $m->diff(
+    commit => $commit,
+    parent => '',
+    file => '',
+    patch => 1,
+);
+$patch = $patch->[0];
+is($patch->{head}, 'diff --git a/file1 b/file1', 'patch->{head} is correct');
+is($patch->{a}, 'a/file1', 'patch->{a} is correct');
+is($patch->{b}, 'b/file1', 'patch->{b} is correct');
+is($patch->{file}, 'file1', 'patch->{file} is correct');
+is($patch->{mode}, '100644', 'patch->{mode} is correct');
+is($patch->{src}, '257cc5642cb1a054f08cc83f2d943e56fd3ebe99', 'patch->{src} is correct');
+is($patch->{index}, 'index 257cc5642cb1a054f08cc83f2d943e56fd3ebe99..5716ca5987cbf97d6bb54920bea6adde242d87e6 100644', 'patch->{index} is correct');
+is($patch->{diff}, '--- a/file1
 +++ b/file1
 @@ -1 +1 @@
 -foo
 +bar
-EOD
+', 'patch->{diff} is correct');
+is($patch->{dst}, '5716ca5987cbf97d6bb54920bea6adde242d87e6', 'patch->{dst} is correct');
+warn(Dumper($patch));
 
 done_testing;