delete repository after failed clone
authorChristian Weiske <cweiske@cweiske.de>
Fri, 28 Sep 2012 10:59:22 +0000 (12:59 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 28 Sep 2012 10:59:22 +0000 (12:59 +0200)
src/phorkie/Forker.php

index f293455a54010187c2c8b667f23d17c204aa5106..7473f1633aad1acf34b50c667618cf5b4772205a 100644 (file)
@@ -32,15 +32,22 @@ class Forker
         //VersionControl_Git wants an existing dir, git clone not
         \rmdir($new->gitDir);
 
         //VersionControl_Git wants an existing dir, git clone not
         \rmdir($new->gitDir);
 
-        $vc->getCommand('clone')
+        $cmd = $vc->getCommand('clone')
             //this should be setOption, but it fails with a = between name and value
             ->addArgument('--separate-git-dir')
             ->addArgument(
                 $GLOBALS['phorkie']['cfg']['gitdir'] . '/' . $new->id . '.git'
             )
             ->addArgument($pathOrUrl)
             //this should be setOption, but it fails with a = between name and value
             ->addArgument('--separate-git-dir')
             ->addArgument(
                 $GLOBALS['phorkie']['cfg']['gitdir'] . '/' . $new->id . '.git'
             )
             ->addArgument($pathOrUrl)
-            ->addArgument($new->workDir)
-            ->execute();
+            ->addArgument($new->workDir);
+        try {
+            $cmd->execute();
+        } catch (\Exception $e) {
+            //clean up, we've got no workdir otherwise
+            $new->delete();
+            throw $e;
+        }
+
         foreach (\glob($new->gitDir . '/hooks/*') as $hookfile) {
             \unlink($hookfile);
         }
         foreach (\glob($new->gitDir . '/hooks/*') as $hookfile) {
             \unlink($hookfile);
         }