Skip to content
Snippets Groups Projects

task#4364 - support branches with slashes

Merged Hahn Axel (hahn) requested to merge task4364-branchname-chars into master
2 files
+ 23
15
Compare changes
  • Side-by-side
  • Inline

Files

@@ -102,6 +102,11 @@ class vcs implements iVcs {
return $this->_aCfg = $aRepoConfig;
}
/**
* set directory für current branch of a project below tempdir
* In it the branch will be initialized
* @return type
*/
private function _setTempdir() {
$this->_sTempDir = $this->_aCfg["url"];
$this->_sTempDir = preg_replace('/[\@\.\:\/]/', '_', $this->_sTempDir);
@@ -213,7 +218,7 @@ class vcs implements iVcs {
* @return array
*/
private function _fetchRemoteBranches($bForceNoCache = false) {
$this->log(__FUNCTION__." start");
$this->log(__FUNCTION__."(bForceNoCache = ".($bForceNoCache ? 'true' : 'false').") start");
$aReturn = array();
if (!$this->getUrl()) {
@@ -227,8 +232,10 @@ class vcs implements iVcs {
// list of cached branch keys
if ($oCache->isExpired() || $bForceNoCache) {
$sWorkdir = dirname($this->_sTempDir) . '/fetchRemoteBranches/';
$this->log(__FUNCTION__." - sWorkdir = $sWorkdir");
$sGitCmd = 'export GIT_SSH="' . $this->_sWrapper . '" ; export PKEY="' . $this->_sKeyfile . '" ; ';
if (!file_exists($sWorkdir . ".git")) {
if (!is_dir($sWorkdir . ".git")) {
$sGitCmd.='mkdir -p "' . $sWorkdir . '" && cd "' . $sWorkdir . '" && ';
$sGitCmd.='git init >/dev/null && ';
$sGitCmd.='git remote add origin "' . $this->getUrl() . '" 2>&1 && ';
@@ -236,9 +243,9 @@ class vcs implements iVcs {
$sGitCmd.='cd "' . $sWorkdir . '" 2>&1 && ';
}
$sGitCmd.='git ls-remote --heads --tags origin 2>&1 ;';
$this->log(__FUNCTION__." start command $sGitCmd");
$this->log(__FUNCTION__." start command <code>$sGitCmd</code>");
exec($sGitCmd, $aOutput, $iRc);
$this->log(__FUNCTION__." end with rc=$iRc ", ($iRc==0 ? 'info':'error'));
$this->log(__FUNCTION__." command ended with rc=$iRc ". '<pre>'.implode("\n", $aOutput).'</pre>', ($iRc==0 ? 'info':'error'));
if ($iRc == 0) {
// use cache that getCommitmessageByBranch can access it
@@ -257,14 +264,14 @@ class vcs implements iVcs {
$this->log(__FUNCTION__ . ' loop over output of git ls-remote <pre>'.print_r($sBranchLine, 1).'</pre>');
$aTmp = explode("\t", $sBranchLine);
$aBranch = explode("/", $aTmp[1]);
$sBranch = array_pop($aBranch); // remove "refs"
$sBranchPath = preg_replace('#^refs/#', '', $aTmp[1]);
$sBranch = preg_replace('#^[a-z]*\/#', '', $sBranchPath);
// skip dereferences
// http://stackoverflow.com/questions/15472107/when-listing-git-ls-remote-why-theres-after-the-tag-name
if (!preg_match('/\^\{\}$/', $sBranch)) {
$sRevision = $aTmp[0];
$sType = array_pop($aBranch);
$sType = preg_replace('#/.*$#', '', $sBranchPath);
$sName = ($sType == "heads") ? "origin/" . $sBranch : $sBranch;
$sBranchKey = $sName;
@@ -419,11 +426,11 @@ class vcs implements iVcs {
}
$sGitCmd.='git log -1 "' . $this->_sCurrentBranch . '" 2>&1 ; '; // 0.0 s
$this->log(__FUNCTION__." start command $sGitCmd");
$this->log(__FUNCTION__." start command <code>$sGitCmd</code>");
// $sLoginfo = shell_exec($sGitCmd);
exec($sGitCmd, $aOutput, $iRc);
$this->log(__FUNCTION__." command ended with rc=$iRc ". '<pre>'.implode("\n", $aOutput).'</pre>', ($iRc==0 ? 'info':'error'));
$sLoginfo= implode("\n", $aOutput);
$this->log(__FUNCTION__." end with rc=$iRc <pre>$sLoginfo</pre>", ($iRc==0 ? 'info':'error'));
/*
*
@@ -490,7 +497,7 @@ class vcs implements iVcs {
$sBranchname = str_replace("origin/", "", $this->_sCurrentBranch);
$sGitCmd = 'export GIT_SSH="' . $this->_sWrapper . '" ; export PKEY="' . $this->_sKeyfile . '" ; ';
$sReturn=false;
$aOutput=false;
$iRc=false;
// this does not checkout tags in git v1.7 - only branches:
@@ -499,18 +506,18 @@ class vcs implements iVcs {
//
$sGitCmd .= 'echo git clone "' . $this->getUrl() . '" "'.$sWorkDir.'" 2>&1 \&\& cd "'.$sWorkDir.'" \&\& git checkout "' . $sBranchname . '" ; ';
$sGitCmd .= ' git clone "' . $this->getUrl() . '" "'.$sWorkDir.'" 2>&1 && cd "'.$sWorkDir.'" && git checkout "' . $sBranchname . '" 2>&1 ';
$this->log(__FUNCTION__." start command $sGitCmd");
$this->log(__FUNCTION__." start command <code>$sGitCmd</code>");
// $sReturn = shell_exec($sGitCmd);
exec($sGitCmd, $sReturn, $iRc);
$this->log(__FUNCTION__." end command $sGitCmd");
return implode("\n", $sReturn). "\nrc=$iRc";
exec($sGitCmd, $aOutput, $iRc);
$this->log(__FUNCTION__." command ended with rc=$iRc ". '<pre>'.implode("\n", $aOutput).'</pre>', ($iRc==0 ? 'info':'error'));
return implode("\n", $aOutput). "\nrc=$iRc";
}
/**
* return url to vcs sources
*/
public function getUrl() {
$this->log(__FUNCTION__." start");
$this->log(__FUNCTION__." --> ".$this->_aCfg["url"]);
return $this->_aCfg["url"];
}
Loading