Fix showing diffs for adding files on the first revision in the repository
authorChuck Hagenbuch <chuck@horde.org>
Sun, 28 Nov 2010 03:54:26 +0000 (22:54 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Sun, 28 Nov 2010 03:54:26 +0000 (22:54 -0500)
framework/Vcs/lib/Horde/Vcs.php
framework/Vcs/lib/Horde/Vcs/Git.php

index 22c4955..3ac0eff 100644 (file)
@@ -261,8 +261,7 @@ class Horde_Vcs
             'ws' => true
         ), $opts);
 
-        $this->assertValidRevision($rev1);
-        $this->assertValidRevision($rev2);
+        if ($rev1) { $this->assertValidRevision($rev1); }
 
         $diff = $this->_diff($file, $rev1, $rev2, $opts);
         return empty($opts['human'])
index b57ec1d..543e9df 100644 (file)
@@ -260,18 +260,21 @@ class Horde_Vcs_Git extends Horde_Vcs
             $flags .= ' -b -w ';
         }
 
-        switch ($opts['type']) {
-        case 'unified':
-            $flags .= '--unified=' . escapeshellarg((int)$opts['num']);
-            break;
-        }
+        if (!$rev1) {
+            $command = $this->getCommand() . ' show --oneline ' . escapeshellarg($rev2) . ' -- ' . escapeshellarg($file->queryModulePath()) . ' 2>&1';
+        } else {
+            switch ($opts['type']) {
+            case 'unified':
+                $flags .= '--unified=' . escapeshellarg((int)$opts['num']);
+                break;
+            }
 
-        // @TODO: add options for $hr options - however these may not
-        // be compatible with some diffs.
-        $command = $this->getCommand() . ' diff -M -C ' . $flags . ' --no-color ' . escapeshellarg($rev1 . '..' . $rev2) . ' -- ' . escapeshellarg($file->queryModulePath()) . ' 2>&1';
+            // @TODO: add options for $hr options - however these may not
+            // be compatible with some diffs.
+            $command = $this->getCommand() . ' diff -M -C ' . $flags . ' --no-color ' . escapeshellarg($rev1 . '..' . $rev2) . ' -- ' . escapeshellarg($file->queryModulePath()) . ' 2>&1';
+        }
 
         exec($command, $diff, $retval);
-
         return $diff;
     }