app\models\Project::getSvnDeployBranchFromDir PHP Method

getSvnDeployBranchFromDir() public static method

拼接宿主机的SVN仓库目录(带branches/tags目录)
public static getSvnDeployBranchFromDir ( string $branchName = 'trunk' ) : string
$branchName string
return string
    public static function getSvnDeployBranchFromDir($branchName = 'trunk')
    {
        $deployFromDir = static::getDeployFromDir();
        if ($branchName == '') {
            $branchFromDir = $deployFromDir;
        } elseif ($branchName == 'trunk') {
            $branchFromDir = sprintf('%s/trunk', $deployFromDir);
        } elseif (static::$CONF->repo_mode == static::REPO_MODE_BRANCH) {
            $branchFromDir = sprintf('%s/branches/%s', $deployFromDir, $branchName);
        } elseif (static::$CONF->repo_mode == static::REPO_MODE_TAG) {
            $branchFromDir = sprintf('%s/tags/%s', $deployFromDir, $branchName);
        }
        return $branchFromDir;
    }

Usage Example

Example #1
0
 /**
  * 初始化宿主机部署工作空间
  *
  * @param TaskModel $task
  * @return bool|int
  */
 public function initLocalWorkspace(TaskModel $task)
 {
     $version = $task->link_id;
     $branch = $task->branch;
     if ($this->config->repo_type == Project::REPO_SVN) {
         // svn cp 过来指定分支的目录, 然后 svn up 到指定版本
         $cmd[] = sprintf('cp -rf %s %s ', Project::getSvnDeployBranchFromDir($branch), Project::getDeployWorkspace($version));
     } else {
         // git cp 仓库, 然后 checkout 切换分支, up 到指定版本
         $cmd[] = sprintf('cp -rf %s %s ', Project::getDeployFromDir(), Project::getDeployWorkspace($version));
     }
     $command = join(' && ', $cmd);
     return $this->runLocalCommand($command);
 }