ENHANCEMENT: phing checkout task now stashes local content before performing checkout and has the option to exclude the base (silverstripe-installer) folder
This commit is contained in:
parent
73a5fb5e62
commit
24705fd9f5
27
build.xml
27
build.xml
|
@ -14,6 +14,7 @@ phing help
|
|||
<taskdef name="findRepos" classname="tools.FindRepositoriesTask" classpath="${project.basedir}" />
|
||||
<taskdef name="ssmodules" classname="tools.LoadModulesTask" classpath="${project.basedir}" />
|
||||
<taskdef name="sschanglog" classname="tools.CreateChangelog" classpath="${project.basedir}" />
|
||||
<taskdef name="gitstash" classname="tools.GitStashTask" classpath="${project.basedir}" />
|
||||
|
||||
<property name="basedir" value="." override="true" />
|
||||
<property name="dependent-modules-file" value="dependent-modules" override="true" />
|
||||
|
@ -21,7 +22,7 @@ phing help
|
|||
<property name="ni_build" value="false" override="true"/> <!-- Prompt if local changes would be overwritten by update -->
|
||||
<property name="changelogFile" value="changelog.md" override="true"/>
|
||||
<property name="changelogSort" value="type" override="true"/>
|
||||
|
||||
|
||||
<available file="${dependent-modules-file}" property="dependent-modules-file-exists" />
|
||||
<available file="${changelog-definition-file}" property="changelog-definition-file-exists" />
|
||||
|
||||
|
@ -93,10 +94,16 @@ Options:
|
|||
|
||||
<!-- Checkout the specified tag on all working copies -->
|
||||
<target name="checkoutTask" if="reponame,gitPath1,tagname">
|
||||
<echo msg="checking out ${reponame}"/>
|
||||
<gitstash repository="${reponame}" gitPath="${gitPath1}" />
|
||||
|
||||
<gitcheckout
|
||||
repository="${reponame}"
|
||||
branchname="${tagname}"
|
||||
gitPath="${gitPath1}" />
|
||||
|
||||
<gitstash repository="${reponame}" gitPath="${gitPath1}" pop="true" />
|
||||
|
||||
<echo msg="checked out ${tagname} tag/branch in '${reponame}' git repository" />
|
||||
</target>
|
||||
|
||||
|
@ -196,6 +203,24 @@ Options:
|
|||
</else>
|
||||
</if>
|
||||
|
||||
<if>
|
||||
<isset property="includeBaseDir"/>
|
||||
<then>
|
||||
<echo msg="Including BaseDir in checkout: ${includeBaseDir}"/>
|
||||
</then>
|
||||
<else>
|
||||
<input propertyName="includeBaseDir" validArgs="yes,no" promptChar=":">Include the base dir '${basedir}' in checkout?</input>
|
||||
<echo msg="Including BaseDir in checkout: ${includeBaseDir}"/>
|
||||
</else>
|
||||
</if>
|
||||
|
||||
<if>
|
||||
<isfalse value="${includeBaseDir}"/>
|
||||
<then><!-- get a list of git repos without the base dir -->
|
||||
<findRepos TargetDir="${basedir}" includeTarget="${includeBaseDir}"/>
|
||||
</then>
|
||||
</if>
|
||||
|
||||
<!-- find all git repos and run the checkoutTask on them -->
|
||||
<foreach list="${GitReposList}" param="reponame" target="checkoutTask" />
|
||||
</target>
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Git stashes a particular folder
|
||||
* @author jseide
|
||||
*
|
||||
*/
|
||||
class GitStashTask extends SilverStripeBuildTask {
|
||||
private $repository = null;
|
||||
private $gitPath = null;
|
||||
private $pop = false;
|
||||
|
||||
public function setRepository($repo) {
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue