Fix bug in Git_Tree::construct() involving array paths.
authorEdward Z. Yang <edwardzyang@thewritingpot.com>
Sun, 20 Jul 2008 01:43:30 +0000 (19 21:43 -0400)
committerEdward Z. Yang <edwardzyang@thewritingpot.com>
Sun, 20 Jul 2008 01:43:30 +0000 (19 21:43 -0400)
Python has the ability to pass magical arguments using * and **. I didn't
realize this when originally porting, so the arguments are passed wrong in
the PHP version. Note, calling __call() directly is a bit hacky, although
it is closest to the Python semantics.

Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
library/Git/Tree.php
tests/Git/TreeTest.php

index 483bde9..e301735 100644 (file)
@@ -32,8 +32,7 @@ class Git_Tree extends Git_Lazy {
      * Constructs and fully initializes a tree.
      */
     public static function construct($repo, $treeish, $paths = array()) {
-        // suspect:
-        $output = $repo->git->lsTree($treeish, $paths);
+        $output = $repo->git->__call('lsTree', array_merge($paths, array($treeish)));
         $tree = new Git_Tree($repo, array('id' => $treeish));
         $tree->constructInitialize($repo, $treeish, $output);
         return $tree;
index 2b17459..f778c47 100644 (file)
@@ -10,8 +10,8 @@ class Git_TreeTest extends GitHarness {
     function testContentsShouldCache() {
         $this->git->setReturnValue('__call', $this->fixture('ls_tree_a') . $this->fixture('ls_tree_b'));
         $this->git->expectCallCount('__call', 2);
-        $this->git->expectAt(0, '__call', array('lsTree', array('master', array())));
-        $this->git->expectAt(1, '__call', array('lsTree', array('34868e6e7384cb5ee51c543a8187fdff2675b5a7', array())));
+        $this->git->expectAt(0, '__call', array('lsTree', array('master')));
+        $this->git->expectAt(1, '__call', array('lsTree', array('34868e6e7384cb5ee51c543a8187fdff2675b5a7')));
         $tree = $this->repo->tree('master');
         list($child) = array_slice($tree->contents, -1);
         $child->contents;
@@ -48,14 +48,14 @@ class Git_TreeTest extends GitHarness {
         // files, which shouldn't have any bearing either. We have condensed
         // those tests.
         $this->git->setReturnValue('__call', $this->fixture('ls_tree_a'));
-        $this->git->expectOnce('__call', array('lsTree', array('master', array())));
+        $this->git->expectOnce('__call', array('lsTree', array('master')));
         $tree = $this->repo->tree('master');
         $this->assertIdentical('aa06ba24b4e3f463b3c4a85469d0fb9e5b421cf8', $tree->get('lib')->id);
         $this->assertIdentical('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', $tree->get('README.txt')->id);
     }
     function testGetWithCommits() {
         $this->git->setReturnValue('__call', $this->fixture('ls_tree_commit'));
-        $this->git->expectOnce('__call', array('lsTree', array('master', array())));
+        $this->git->expectOnce('__call', array('lsTree', array('master')));
         $tree = $this->repo->tree('master');
         $this->assertIdentical($tree->get('bar'), null);
         $this->assertIdentical('2afb47bcedf21663580d5e6d2f406f08f3f65f19', $tree->get('foo')->id);