From 511b4df311def0f5d6e3ce8f8882f1a1eca807c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=CC=81o=20POIROUX?= Date: Mon, 24 Feb 2014 12:08:32 +0100 Subject: [PATCH 1/2] Deploy in an existing directory --- lib/Pomander/Scm/Git.php | 20 +++++++++++++++----- lib/tasks/deploy.php | 3 +-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/Pomander/Scm/Git.php b/lib/Pomander/Scm/Git.php index 53592f2..f0c8aca 100644 --- a/lib/Pomander/Scm/Git.php +++ b/lib/Pomander/Scm/Git.php @@ -16,7 +16,17 @@ class Git extends Scm */ public function create($location) { - return "git clone -q {$this->repository} {$location}"; + $cmd = array(); + + $cmd[] = "cd {$location}"; + $cmd[] = "rm -rf .git"; + $cmd[] = "rm -rf REVISION"; + $cmd[] = "git init -q"; + $cmd[] = "git remote add origin {$this->repository}"; + $cmd[] = "git fetch origin -q"; + $cmd[] = "git reset --hard origin/master -q"; + + return implode(' && ', $cmd); } /** @@ -32,12 +42,12 @@ public function update() $cmd[] = "git fetch --tags -q {$remote}"; // Search revision - if(!empty($this->app->env->revision)) { + if (!empty($this->app->env->revision)) { $commit = $this->app->env->revision; } else { - if(!empty($this->app["branch"])) { + if (!empty($this->app["branch"])) { $commit = $this->get_commit_sha($this->app["branch"]); - } elseif(!empty($this->app->env->branch)) { + } elseif (!empty($this->app->env->branch)) { $commit = $this->get_commit_sha($this->app->env->branch); } else { $commit = 'HEAD'; @@ -71,7 +81,7 @@ public function revision() public function get_commit_sha($ref) { // if specifying a remote ref, just grab the branch name - if(strpos($ref, "/") !== false) { + if (strpos($ref, "/") !== false) { $ref = explode("/", $ref); $ref = end($ref); } diff --git a/lib/tasks/deploy.php b/lib/tasks/deploy.php index 428a7ed..277d9ec 100644 --- a/lib/tasks/deploy.php +++ b/lib/tasks/deploy.php @@ -7,11 +7,10 @@ info("deploy","setting up environment"); $cmd = array( "umask {$app->env->umask}", - "mkdir -p {$app->env->deploy_to}" + "if test ! -d {$app->env->deploy_to}; then mkdir -p {$app->env->deploy_to}; fi" ); if ($app->env->releases === false) { - $cmd[] = "rm -rf {$app->env->deploy_to}"; $cmd[] = $app->env->scm->create($app->env->deploy_to); } else { $deployed = run("if test -d {$app->env->current_dir}; then echo \"exists\"; fi", true); From 09e912722f3f34dbdf266a68a1a40812885a40ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=CC=81o=20POIROUX?= Date: Tue, 25 Feb 2014 21:31:47 +0100 Subject: [PATCH 2/2] Refork to succeed the phpunit (now setup make an update) --- lib/Pomander/Scm/Git.php | 14 ++++++++------ lib/tasks/deploy.php | 4 ---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/Pomander/Scm/Git.php b/lib/Pomander/Scm/Git.php index f0c8aca..325ef11 100644 --- a/lib/Pomander/Scm/Git.php +++ b/lib/Pomander/Scm/Git.php @@ -18,15 +18,17 @@ public function create($location) { $cmd = array(); + $cmd[] = "umask {$this->app->env->umask}"; + $cmd[] = "if test ! -d {$location}; then mkdir {$location}; fi"; + + $cmd[] = "rm -rf {$location}/*"; $cmd[] = "cd {$location}"; - $cmd[] = "rm -rf .git"; - $cmd[] = "rm -rf REVISION"; $cmd[] = "git init -q"; - $cmd[] = "git remote add origin {$this->repository}"; - $cmd[] = "git fetch origin -q"; - $cmd[] = "git reset --hard origin/master -q"; - return implode(' && ', $cmd); + $remote = isset($this->app->env->remote)? $this->app->env->remote : "origin"; + $cmd[] = "git remote add {$remote} {$this->repository}"; + + return implode(' && ', $cmd) . ' && ' . $this->update(); } /** diff --git a/lib/tasks/deploy.php b/lib/tasks/deploy.php index 277d9ec..19ed5d4 100644 --- a/lib/tasks/deploy.php +++ b/lib/tasks/deploy.php @@ -5,10 +5,6 @@ desc("Setup application in environment."); task('setup','app', function ($app) { info("deploy","setting up environment"); - $cmd = array( - "umask {$app->env->umask}", - "if test ! -d {$app->env->deploy_to}; then mkdir -p {$app->env->deploy_to}; fi" - ); if ($app->env->releases === false) { $cmd[] = $app->env->scm->create($app->env->deploy_to);