Skip to content
Snippets Groups Projects
Commit 2f776352 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch 'task4364-branchname-chars' into 'master'

task#4364 - support branches with slashes

See merge request !2
parents dbbcb1ee 0375b818
Branches
No related tags found
1 merge request!2task#4364 - support branches with slashes
Pipeline #218 passed
...@@ -27,4 +27,5 @@ nbproject ...@@ -27,4 +27,5 @@ nbproject
/public_html/vendor/medoo/ /public_html/vendor/medoo/
/config/_inc_projects_config.php /config/_inc_projects_config.php
/config/inc_projects_config.php /config/inc_projects_config.php
/config/inc_user2roles.php
/.vscode/ /.vscode/
\ No newline at end of file
...@@ -102,6 +102,11 @@ class vcs implements iVcs { ...@@ -102,6 +102,11 @@ class vcs implements iVcs {
return $this->_aCfg = $aRepoConfig; 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() { private function _setTempdir() {
$this->_sTempDir = $this->_aCfg["url"]; $this->_sTempDir = $this->_aCfg["url"];
$this->_sTempDir = preg_replace('/[\@\.\:\/]/', '_', $this->_sTempDir); $this->_sTempDir = preg_replace('/[\@\.\:\/]/', '_', $this->_sTempDir);
...@@ -213,7 +218,7 @@ class vcs implements iVcs { ...@@ -213,7 +218,7 @@ class vcs implements iVcs {
* @return array * @return array
*/ */
private function _fetchRemoteBranches($bForceNoCache = false) { private function _fetchRemoteBranches($bForceNoCache = false) {
$this->log(__FUNCTION__." start"); $this->log(__FUNCTION__."(bForceNoCache = ".($bForceNoCache ? 'true' : 'false').") start");
$aReturn = array(); $aReturn = array();
if (!$this->getUrl()) { if (!$this->getUrl()) {
...@@ -227,8 +232,10 @@ class vcs implements iVcs { ...@@ -227,8 +232,10 @@ class vcs implements iVcs {
// list of cached branch keys // list of cached branch keys
if ($oCache->isExpired() || $bForceNoCache) { if ($oCache->isExpired() || $bForceNoCache) {
$sWorkdir = dirname($this->_sTempDir) . '/fetchRemoteBranches/'; $sWorkdir = dirname($this->_sTempDir) . '/fetchRemoteBranches/';
$this->log(__FUNCTION__." - sWorkdir = $sWorkdir");
$sGitCmd = 'export GIT_SSH="' . $this->_sWrapper . '" ; export PKEY="' . $this->_sKeyfile . '" ; '; $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.='mkdir -p "' . $sWorkdir . '" && cd "' . $sWorkdir . '" && ';
$sGitCmd.='git init >/dev/null && '; $sGitCmd.='git init >/dev/null && ';
$sGitCmd.='git remote add origin "' . $this->getUrl() . '" 2>&1 && '; $sGitCmd.='git remote add origin "' . $this->getUrl() . '" 2>&1 && ';
...@@ -236,9 +243,9 @@ class vcs implements iVcs { ...@@ -236,9 +243,9 @@ class vcs implements iVcs {
$sGitCmd.='cd "' . $sWorkdir . '" 2>&1 && '; $sGitCmd.='cd "' . $sWorkdir . '" 2>&1 && ';
} }
$sGitCmd.='git ls-remote --heads --tags origin 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); 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) { if ($iRc == 0) {
// use cache that getCommitmessageByBranch can access it // use cache that getCommitmessageByBranch can access it
...@@ -257,14 +264,14 @@ class vcs implements iVcs { ...@@ -257,14 +264,14 @@ class vcs implements iVcs {
$this->log(__FUNCTION__ . ' loop over output of git ls-remote <pre>'.print_r($sBranchLine, 1).'</pre>'); $this->log(__FUNCTION__ . ' loop over output of git ls-remote <pre>'.print_r($sBranchLine, 1).'</pre>');
$aTmp = explode("\t", $sBranchLine); $aTmp = explode("\t", $sBranchLine);
$aBranch = explode("/", $aTmp[1]); $sBranchPath = preg_replace('#^refs/#', '', $aTmp[1]);
$sBranch = array_pop($aBranch); // remove "refs" $sBranch = preg_replace('#^[a-z]*\/#', '', $sBranchPath);
// skip dereferences // skip dereferences
// http://stackoverflow.com/questions/15472107/when-listing-git-ls-remote-why-theres-after-the-tag-name // http://stackoverflow.com/questions/15472107/when-listing-git-ls-remote-why-theres-after-the-tag-name
if (!preg_match('/\^\{\}$/', $sBranch)) { if (!preg_match('/\^\{\}$/', $sBranch)) {
$sRevision = $aTmp[0]; $sRevision = $aTmp[0];
$sType = array_pop($aBranch); $sType = preg_replace('#/.*$#', '', $sBranchPath);
$sName = ($sType == "heads") ? "origin/" . $sBranch : $sBranch; $sName = ($sType == "heads") ? "origin/" . $sBranch : $sBranch;
$sBranchKey = $sName; $sBranchKey = $sName;
...@@ -419,11 +426,11 @@ class vcs implements iVcs { ...@@ -419,11 +426,11 @@ class vcs implements iVcs {
} }
$sGitCmd.='git log -1 "' . $this->_sCurrentBranch . '" 2>&1 ; '; // 0.0 s $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); // $sLoginfo = shell_exec($sGitCmd);
exec($sGitCmd, $aOutput, $iRc); 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); $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 { ...@@ -490,7 +497,7 @@ class vcs implements iVcs {
$sBranchname = str_replace("origin/", "", $this->_sCurrentBranch); $sBranchname = str_replace("origin/", "", $this->_sCurrentBranch);
$sGitCmd = 'export GIT_SSH="' . $this->_sWrapper . '" ; export PKEY="' . $this->_sKeyfile . '" ; '; $sGitCmd = 'export GIT_SSH="' . $this->_sWrapper . '" ; export PKEY="' . $this->_sKeyfile . '" ; ';
$sReturn=false; $aOutput=false;
$iRc=false; $iRc=false;
// this does not checkout tags in git v1.7 - only branches: // this does not checkout tags in git v1.7 - only branches:
...@@ -499,18 +506,18 @@ class vcs implements iVcs { ...@@ -499,18 +506,18 @@ class vcs implements iVcs {
// //
$sGitCmd .= 'echo git clone "' . $this->getUrl() . '" "'.$sWorkDir.'" 2>&1 \&\& cd "'.$sWorkDir.'" \&\& git checkout "' . $sBranchname . '" ; '; $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 '; $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); // $sReturn = shell_exec($sGitCmd);
exec($sGitCmd, $sReturn, $iRc); exec($sGitCmd, $aOutput, $iRc);
$this->log(__FUNCTION__." end command $sGitCmd"); $this->log(__FUNCTION__." command ended with rc=$iRc ". '<pre>'.implode("\n", $aOutput).'</pre>', ($iRc==0 ? 'info':'error'));
return implode("\n", $sReturn). "\nrc=$iRc"; return implode("\n", $aOutput). "\nrc=$iRc";
} }
/** /**
* return url to vcs sources * return url to vcs sources
*/ */
public function getUrl() { public function getUrl() {
$this->log(__FUNCTION__." start"); $this->log(__FUNCTION__." --> ".$this->_aCfg["url"]);
return $this->_aCfg["url"]; return $this->_aCfg["url"];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment