revision display support
[phorkie.git] / src / phorkie / Repository / Post.php
index 8cd9323ca1625f082f2dd2e55eb464a22596b4d2..96e5c1135153203a43eef3934024eb585a2f226e 100644 (file)
@@ -67,12 +67,17 @@ class Repository_Post
             } else if (isset($arFile['delete']) && $arFile['delete'] == 1) {
                 $bDelete = true;
             } else if ($orignalName != $name) {
-                //FIXME: what to do with overwrites?
-                $vc->getCommand('mv')
-                    ->addArgument($orignalName)
-                    ->addArgument($name)
-                    ->execute();
-                $bChanged = true;
+                if (strpos($name, '/') === false) {
+                    //ignore names with a slash in it, would be new directory
+                    //FIXME: what to do with overwrites?
+                    $vc->getCommand('mv')
+                        ->addArgument($orignalName)
+                        ->addArgument($name)
+                        ->execute();
+                    $bChanged = true;
+                } else {
+                    $name = $orignalName;
+                }
             }
 
             $file = $this->repo->getFileByName($name, false);
@@ -83,14 +88,14 @@ class Repository_Post
                 $bChanged = true;
             } else if ($bUpload) {
                 move_uploaded_file(
-                    $_FILES['files']['tmp_name'][$num]['upload'], $file->getPath()
+                    $_FILES['files']['tmp_name'][$num]['upload'], $file->getFullPath()
                 );
                 $command = $vc->getCommand('add')
                     ->addArgument($file->getFilename())
                     ->execute();
                 $bChanged = true;
-            } else if ($bNew || $file->getContent() != $arFile['content']) {
-                file_put_contents($file->getPath(), $arFile['content']);
+            } else if ($bNew || (isset($arFile['content']) && $file->getContent() != $arFile['content'])) {
+                file_put_contents($file->getFullPath(), $arFile['content']);
                 $command = $vc->getCommand('add')
                     ->addArgument($file->getFilename())
                     ->execute();
@@ -114,13 +119,18 @@ class Repository_Post
         $rs = new Repositories();
         $repo = $rs->createNew();
         $vc = $repo->getVc();
-        $vc->initRepository();
-
-        foreach (glob($repo->repoDir . '/.git/hooks/*') as $hookfile) {
+        $vc->getCommand('init')
+            //this should be setOption, but it fails with a = between name and value
+            ->addArgument('--separate-git-dir')
+            ->addArgument($GLOBALS['phorkie']['cfg']['gitdir'] . '/' . $repo->id . '.git')
+            ->addArgument($repo->workDir)
+            ->execute();
+
+        foreach (glob($repo->gitDir . '/hooks/*') as $hookfile) {
             unlink($hookfile);
         }
 
-        touch($repo->repoDir . '/.git/git-daemon-export-ok');
+        touch($repo->gitDir . '/git-daemon-export-ok');
 
         return $repo;
     }
@@ -130,7 +140,7 @@ class Repository_Post
         $num = -1;
         do {
             ++$num;
-            $files = glob($this->repo->repoDir . '/' . $prefix . $num . '.*');
+            $files = glob($this->repo->workDir . '/' . $prefix . $num . '.*');
         } while (count($files));
 
         return $prefix . $num;