From 24705fd9f5f5cd80cb3c998dd4ee6631ee1b8e0b Mon Sep 17 00:00:00 2001 From: Julian Seidenberg Date: Thu, 28 Apr 2011 15:47:48 +1200 Subject: [PATCH] ENHANCEMENT: phing checkout task now stashes local content before performing checkout and has the option to exclude the base (silverstripe-installer) folder --- build.xml | 27 ++++++++++++++++++++- tools/FindRepositoriesTask.php | 23 ++++++++++++++---- tools/GitStashTask.php | 43 ++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 tools/GitStashTask.php diff --git a/build.xml b/build.xml index 3575ed5..4f75b6e 100644 --- a/build.xml +++ b/build.xml @@ -14,6 +14,7 @@ phing help + @@ -21,7 +22,7 @@ phing help - + @@ -93,10 +94,16 @@ Options: + + + + + + @@ -196,6 +203,24 @@ Options: + + + + + + + Include the base dir '${basedir}' in checkout? + + + + + + + + + + + diff --git a/tools/FindRepositoriesTask.php b/tools/FindRepositoriesTask.php index 50eaed7..aa4f2fa 100644 --- a/tools/FindRepositoriesTask.php +++ b/tools/FindRepositoriesTask.php @@ -6,16 +6,19 @@ * */ class FindRepositoriesTask extends Task { - private $items = null; + private $targetDir = null; - private $copy = false; - private $sourceDir = null; + private $includeTarget = true; public function setTargetDir($targetDir) { $this->targetDir = $targetDir; } + public function setIncludeTarget($includeTarget) { + $this->includeTarget = $includeTarget; + } + /** * Recursively lists a folder and includes only those directories that have the filter parameter as a sub-item */ @@ -55,7 +58,19 @@ class FindRepositoriesTask extends Task { $gitDirs = array(); $this->recursiveListDirFilter($this->targetDir, $gitDirs, '.git'); - $this->project->setProperty('GitReposList',implode(',',$gitDirs)); + + $gitDirsOutput = array(); + if (!$this->includeTarget) { //don't include the target dir + foreach($gitDirs as $dir) { + if ($dir != $this->targetDir && $dir != realpath($this->targetDir)) { + $gitDirsOutput[] = $dir; + } + } + } else { + $gitDirsOutput = $gitDirs; + } + + $this->project->setProperty('GitReposList',implode(',',$gitDirsOutput)); } } diff --git a/tools/GitStashTask.php b/tools/GitStashTask.php new file mode 100644 index 0000000..4af925d --- /dev/null +++ b/tools/GitStashTask.php @@ -0,0 +1,43 @@ +repository = $repo; + } + + public function setGitPath($gitPath) { + $this->gitPath = $gitPath; + } + + public function setPop($pop) { + $this->pop = $pop; + } + + public function main() { + if (!is_dir($this->repository)) { + throw new BuildException("Invalid target directory: $this->repository"); + } + + $cwd = realpath(getcwd()); + + chdir($this->repository); + + if ($this->pop == true) $result = parent::exec("$this->gitPath stash pop",true); + else $result = parent::exec("$this->gitPath stash",true); + + if ($result) echo $result; + + chdir($cwd); + } +} + +?> \ No newline at end of file