+ Add create branch method for scm.
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user