set title and homepage of remote forks
[phorkie.git] / src / phorkie / Forker.php
index 7473f1633aad1acf34b50c667618cf5b4772205a..b4ab44968c5bf485f9154427e85e277ec40a2c90 100644 (file)
@@ -6,19 +6,49 @@ class Forker
     public function forkLocal($repo)
     {
         $new = $this->fork($repo->gitDir);
+
         \copy($repo->gitDir . '/description', $new->gitDir . '/description');
+        $new->getVc()
+            ->getCommand('config')
+            ->addArgument('remote.origin.title')
+            ->addArgument(file_get_contents($repo->gitDir . '/description'))
+            ->execute();
+
         $this->index($new);
+
+        $not = new Notificator();
+        $not->create($new);
+
         return $new;
     }
 
-    public function forkRemote($cloneUrl, $originalUrl)
+    public function forkRemote($cloneUrl, $originalUrl, $title = null)
     {
         $new = $this->fork($cloneUrl);
-        file_put_contents(
-            $new->gitDir . '/description',
-            'Fork of ' . $originalUrl
-        );
+
+        $new->getVc()
+            ->getCommand('config')
+            ->addArgument('remote.origin.title')
+            ->addArgument($title)
+            ->execute();
+        if ($originalUrl != $cloneUrl) {
+            $new->getVc()
+                ->getCommand('config')
+                ->addArgument('remote.origin.homepage')
+                ->addArgument($originalUrl)
+                ->execute();
+        }
+
+        if ($title === null) {
+            $title = 'Fork of ' . $originalUrl;
+        }
+        file_put_contents($new->gitDir . '/description', $title);
+
         $this->index($new);
+
+        $not = new Notificator();
+        $not->create($new);
+
         return $new;
     }
 
@@ -48,9 +78,8 @@ class Forker
             throw $e;
         }
 
-        foreach (\glob($new->gitDir . '/hooks/*') as $hookfile) {
-            \unlink($hookfile);
-        }
+        $rs = new Repository_Setup($new);
+        $rs->afterInit();
 
         return $new;
     }