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

fix project setup and changing git url

parent cf06b06b
No related branches found
No related tags found
1 merge request!62V2.0
......@@ -935,7 +935,7 @@ class projectgui extends project {
);
// detect access to repo url
$aBranches=$this->getRemoteBranches();
$aBranches=$this->getRemoteBranches(true);
// $aRepodata = $this->getRepoRevision();
// if (is_array($aRepodata) && array_key_exists("message", $aRepodata)) {
......
......@@ -251,7 +251,8 @@ class vcs implements iVcs {
$this->log(__FUNCTION__."(bIgnoreCache = ".($bIgnoreCache ? 'true' : 'false').") start");
$aReturn = array();
if (!$this->getUrl()) {
$sGitUrl=$this->getUrl();
if (!$sGitUrl) {
return false;
}
......@@ -266,17 +267,29 @@ class vcs implements iVcs {
$this->log(__FUNCTION__." - sWorkdir = $sWorkdir");
$sGitCmd = 'export GIT_SSH="' . $this->_sWrapper . '" ; export PKEY="' . $this->_sKeyfile . '" ; ';
if (is_dir($sWorkdir . ".git")) {
// if a subdir .git exists:
// Verify if git remote -v contains the current git url
// If not, we delete it
$sPreCmd='cd "' . $sWorkdir . '" 2>&1 && git remote -v 2>&1 | grep "' . $sGitUrl . '" >/dev/null || ( echo "DELETING .git dir..."; rm -rf .git && rc=$?; echo "rc=$rc"; sleep 1; exit $rc) ';
$this->log(__FUNCTION__." - start PRE command <code>$sPreCmd</code>");
exec($sPreCmd, $aPreLines, $iRc);
if (!$iRc==0){
$this->log(__FUNCTION__." <code>".print_r($aPreLines, 1)."</code> rc=$iRc");
}
}
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 && ';
$sGitCmd.='git remote add origin "' . $sGitUrl . '" 2>&1 && ';
} else {
$sGitCmd.='cd "' . $sWorkdir . '" 2>&1 && ';
}
$sGitCmd.='git ls-remote --heads --tags origin 2>&1 ;';
$this->log(__FUNCTION__." start command <code>$sGitCmd</code>");
$this->log(__FUNCTION__." - start command <code>$sGitCmd</code>");
exec($sGitCmd, $aOutput, $iRc);
$this->log(__FUNCTION__." command ended with rc=$iRc ". '<pre>'.implode("\n", $aOutput).'</pre>', ($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
......@@ -324,9 +337,12 @@ class vcs implements iVcs {
$this->_aRemoteBranches = $aReturn;
$this->log(__FUNCTION__ . ' '.count($aReturn).' branches: <pre>'.print_r($this->_aRemoteBranches, 1).'</pre>');
$this->_cacheRemoteBranches();
}
} else {
$this->_aRemoteBranches = $oCache->read();
// $this->_aRemoteBranches = $oCache->read();
$this->log(__FUNCTION__." - No git access? --> deleting cache of former fetched branches...");
$oCache->delete();
$this->_aRemoteBranches = [];
}
}
return $this->_aRemoteBranches;
}
......@@ -339,8 +355,10 @@ class vcs implements iVcs {
public function getRemoteBranches($bIgnoreCache=false) {
$this->log(__FUNCTION__."($bIgnoreCache) start");
if (!$this->_aRemoteBranches || $bIgnoreCache) {
$this->log(__FUNCTION__."($bIgnoreCache) uncached");
$this->log(__FUNCTION__."($bIgnoreCache) --> fetching fresh data");
$this->_fetchRemoteBranches($bIgnoreCache);
} else {
$this->log(__FUNCTION__."($bIgnoreCache) --> returning cached data");
}
return $this->_aRemoteBranches;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment