-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from tamagokun/better_deploy_update
[Review] Improving deploy:update closes #39
- Loading branch information
Showing
7 changed files
with
108 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
vendor | ||
deploy | ||
tests/test_release | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
namespace Pomander; | ||
|
||
use phake\Application; | ||
use \phake\Application; | ||
|
||
class Cli | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,90 @@ | ||
<?php | ||
|
||
namespace Pomander\Scm; | ||
|
||
class Git extends \Pomander\Scm | ||
use Pomander\Scm; | ||
|
||
/** | ||
* Class Git | ||
* @package Pomander\Scm | ||
*/ | ||
class Git extends Scm | ||
{ | ||
/** | ||
* @param $location | ||
* @return string | ||
*/ | ||
public function create($location) | ||
{ | ||
return "git clone {$this->repository} {$location}"; | ||
return "git clone -q {$this->repository} {$location}"; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function update() | ||
{ | ||
if (!empty($this->app->env->branch)) { | ||
$cmd = "git reset --hard --quiet && git checkout {$this->app->env->branch} --quiet && git pull --quiet"; | ||
} elseif (!empty($this->app->env->revision)) { | ||
$cmd = "git reset --hard {$this->app->env->revision} --quiet"; | ||
} else { | ||
$cmd = 'git reset --hard HEAD --quiet && git pull --quiet'; | ||
$cmd = array(); | ||
|
||
// Fetch remote | ||
$remote = isset($this->app->env->remote)? $this->app->env->remote : "origin"; | ||
$cmd[] = "git fetch -q {$remote}"; | ||
$cmd[] = "git fetch --tags -q {$remote}"; | ||
|
||
// Search revision | ||
if(!empty($this->app->env->revision)) { | ||
$commit = $this->app->env->revision; | ||
} | ||
else { | ||
if(!empty($this->app["branch"])) { | ||
$commit = $this->get_commit_sha($this->app["branch"]); | ||
} elseif(!empty($this->app->env->branch)) { | ||
$commit = $this->get_commit_sha($this->app->env->branch); | ||
} else { | ||
$commit = 'HEAD'; | ||
} | ||
} | ||
|
||
// Reset HARD commit | ||
$cmd[] = "git reset -q --hard {$commit}"; | ||
|
||
if ($this->app->env->submodule !== false) { | ||
$cmd .= ' && git submodule update --init --recursive --quiet'; | ||
$cmd[] = 'git submodule update --init --recursive --quiet'; | ||
} | ||
|
||
$cmd .= ' && git log --date=relative --format=format:"%C(bold blue)(%ar)%C(reset) // %an \'%s\' %C(bold green)(%h)%C(reset)" | head -1'; | ||
$cmd[] = 'git clean -q -d -x -f'; | ||
$cmd[] = 'git log --date=relative --format=format:"%C(bold blue)(%ar)%C(reset) %an \'%s\' %C(bold green)(%h)%C(reset)" | head -1'; | ||
|
||
return $cmd; | ||
return implode(' && ', $cmd); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function revision() | ||
{ | ||
return "echo -e `git log --pretty=format:'%H' -n 1`"; | ||
return "git rev-parse HEAD"; | ||
} | ||
|
||
/** | ||
* @param $ref | ||
* @return string|void | ||
*/ | ||
public function get_commit_sha($ref) | ||
{ | ||
// if specifying a remote ref, just grab the branch name | ||
if(strpos($ref, "/") !== false) { | ||
$ref = explode("/", $ref); | ||
$ref = end($ref); | ||
} | ||
|
||
list($status, $commit) = run_local("git ls-remote {$this->app->env->repository} {$ref}"); | ||
if($status > 0 || !$commit) abort("update", "failed to retrieve commit for {$ref}."); | ||
|
||
$commit = array_shift($commit); | ||
$commit = substr($commit, 0, strpos($commit, "\t")); | ||
|
||
return $commit; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters