* Modify branch get.

This commit is contained in:
caoyanyi
2022-07-26 16:16:17 +08:00
parent 91a99a6cdb
commit c10c25b84d
3 changed files with 15 additions and 8 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ ALTER TABLE `zt_mr` CHANGE COLUMN `gitlabID` `hostID` mediumint(8) UNSIGNED NOT
ALTER TABLE `zt_mr` MODIFY COLUMN `sourceProject` varchar(50) NOT NULL AFTER `hostID`;
ALTER TABLE `zt_mr` MODIFY COLUMN `targetProject` varchar(50) NOT NULL AFTER `sourceBranch`;
UPDATE `zt_project` SET `status`='closed' WHERE `type` IN ('sprint', 'stage', 'kanban') AND `model`='' AND `status` = 'done';
ALTER TABLE `zt_repo` ADD COLUMN `serviceHost` int(10) NOT NULL AFTER `client`;
ALTER TABLE `zt_repo` ADD COLUMN `serviceHost` varchar(50) NOT NULL AFTER `client`;
ALTER TABLE `zt_repo` ADD COLUMN `serviceProject` varchar(100) NOT NULL AFTER `serviceHost`;
UPDATE `zt_repo` SET `serviceHost` = `client`, `serviceProject` = `path` WHERE `SCM` = 'Gitlab';
UPDATE `zt_repo` SET `client` = '', `path` = '' WHERE `SCM` = 'Gitlab';
+6 -5
View File
@@ -21,7 +21,7 @@ class Gitea
$this->client = $client;
$this->root = rtrim($root, DIRECTORY_SEPARATOR);
$this->branch = isset($_COOKIE['repoBranch']) ? $_COOKIE['repoBranch'] : '';
$this->branch = isset($_COOKIE['repoBranch']) ? 'origin/' . $_COOKIE['repoBranch'] : '';
chdir($this->root);
exec("{$this->client} config core.quotepath false");
@@ -127,7 +127,7 @@ class Gitea
chdir($this->root);
/* Get local branch. */
$cmd = escapeCmd("$this->client branch -r");
$cmd = escapeCmd("$this->client branch -a");
$list = execCmd($cmd . ' 2>&1', 'array', $result);
if($result) return array();
@@ -139,10 +139,9 @@ class Gitea
foreach($list as $localBranch)
{
$localBranch = trim($localBranch);
if(substr($localBranch, 0, 11) == 'origin/HEAD') continue;
if(substr($localBranch, 0, 19) == 'remotes/origin/HEAD') continue;
if(substr($localBranch, 0, 1) == '*') $localBranch = substr($localBranch, 1);
if(substr($localBranch, 0, 7) == 'origin/') $localBranch = substr($localBranch, 7);
if(substr($localBranch, 0, 15) == 'remotes/origin/') $localBranch = substr($localBranch, 15);
$localBranch = trim($localBranch);
if(empty($localBranch))continue;
@@ -538,6 +537,8 @@ class Gitea
$count = $count == 0 ? '' : "-n $count";
chdir($this->root);
if($branch) execCmd(escapeCmd("$this->client checkout $branch"), 'array');
$list = execCmd(escapeCmd("$this->client log $count $revision -- ./"), 'array');
$commits = $this->parseLog($list);
+8 -2
View File
@@ -21,7 +21,7 @@ class GitRepo
$this->client = $client;
$this->root = rtrim($root, DIRECTORY_SEPARATOR);
$this->branch = isset($_COOKIE['repoBranch']) ? $_COOKIE['repoBranch'] : '';
$this->branch = isset($_COOKIE['repoBranch']) ? 'origin/' . $_COOKIE['repoBranch'] : '';
chdir($this->root);
exec("{$this->client} config core.quotepath false");
@@ -127,17 +127,21 @@ class GitRepo
chdir($this->root);
/* Get local branch. */
$cmd = escapeCmd("$this->client branch");
$cmd = escapeCmd("$this->client branch -a");
$list = execCmd($cmd . ' 2>&1', 'array', $result);
if($result) return array();
/* Get default branch. */
$defaultBranch = execCmd("$this->client symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'");
$defaultBranch = trim($defaultBranch);
$branches = array();
foreach($list as $localBranch)
{
$localBranch = trim($localBranch);
if(substr($localBranch, 0, 19) == 'remotes/origin/HEAD') continue;
if(substr($localBranch, 0, 1) == '*') $localBranch = substr($localBranch, 1);
if(substr($localBranch, 0, 15) == 'remotes/origin/') $localBranch = substr($localBranch, 15);
$localBranch = trim($localBranch);
if(empty($localBranch))continue;
@@ -533,6 +537,8 @@ class GitRepo
$count = $count == 0 ? '' : "-n $count";
chdir($this->root);
if($branch) execCmd(escapeCmd("$this->client checkout $branch"), 'array');
$list = execCmd(escapeCmd("$this->client log $count $revision -- ./"), 'array');
$commits = $this->parseLog($list);