+ Add create branch method for scm.

This commit is contained in:
caoyanyi
2023-10-31 14:20:41 +08:00
parent c33d55bc86
commit efa6f36053
5 changed files with 88 additions and 0 deletions
+18
View File
@@ -178,6 +178,24 @@ class Gitea
return $branches;
}
/**
* Create a branch.
*
* @param string $branchName
* @param string $ref
* @access public
* @return bool
*/
public function createBranch($branchName = '', $ref = 'master')
{
chdir($this->root);
$res = execCmd(escapeCmd("{$this->client} checkout -b {$branchName} origin/{$ref}"), 'array');
if(empty($res[0])) return array('result' => 'fail', 'message' => 'Branch is exists.');
execCmd(escapeCmd("{$this->client} push origin {$branchName}"), 'array');
return array('result' => 'success', 'message' => '');
}
/**
* Get last log.
*
+19
View File
@@ -199,6 +199,25 @@ class gitlab
return $branches;
}
/**
* Create a branch.
*
* @param string $branchName
* @param string $ref
* @access public
* @return bool
*/
public function createBranch($branchName = '', $ref = 'master')
{
$param = new stdclass();
$param->ref = $ref;
$param->branch = $branchName;
$api = $this->root . 'branches?private_token=' . $this->token;
$result = json_decode(commonModel::http($api, $param));
return array('result' => empty($result->name) ? 'fail' : 'success', 'message' => $result->message);
}
/**
* Get last log.
*
+18
View File
@@ -166,6 +166,24 @@ class GitRepo
return $branches;
}
/**
* Create a branch.
*
* @param string $branchName
* @param string $ref
* @access public
* @return bool
*/
public function createBranch($branchName = '', $ref = 'master')
{
chdir($this->root);
$res = execCmd(escapeCmd("{$this->client} checkout -b {$branchName} origin/{$ref}"), 'array');
if(empty($res[0])) return array('result' => 'fail', 'message' => 'Branch is exists.');
execCmd(escapeCmd("{$this->client} push origin {$branchName}"), 'array');
return array('result' => 'success', 'message' => '');
}
/**
* Get last log.
*
+18
View File
@@ -178,6 +178,24 @@ class Gogs
return $branches;
}
/**
* Create a branch.
*
* @param string $branchName
* @param string $ref
* @access public
* @return bool
*/
public function createBranch($branchName = '', $ref = 'master')
{
chdir($this->root);
$res = execCmd(escapeCmd("{$this->client} checkout -b {$branchName} origin/{$ref}"), 'array');
if(empty($res[0])) return array('result' => 'fail', 'message' => 'Branch is exists.');
execCmd(escapeCmd("{$this->client} push origin {$branchName}"), 'array');
return array('result' => 'success', 'message' => '');
}
/**
* Get last log.
*
+15
View File
@@ -58,6 +58,21 @@ class scm
return $this->engine->branch();
}
/**
* Create a branch.
*
* @param string $branchName
* @param string $ref
* @access public
* @return bool
*/
public function createBranch($branchName = '', $ref = 'master')
{
if(get_class($this->engine) == 'subversion') return false;
return $this->engine->createBranch($branchName, $ref);
}
/**
* Get log.
*