From 5c02cd0e833acd7f4f84a001b27d944911404db9 Mon Sep 17 00:00:00 2001 From: wushuiyong Date: Thu, 19 Nov 2015 22:44:41 +0800 Subject: [PATCH] Compatible with svn without trunk/tags/branches --- components/Svn.php | 37 ++++++++++++++++++++++++------------- messages/en/w.php | 1 + messages/zh/w.php | 1 + views/task/submit-svn.php | 2 +- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/components/Svn.php b/components/Svn.php index 088355a9..6259f77d 100644 --- a/components/Svn.php +++ b/components/Svn.php @@ -45,7 +45,9 @@ public function updateToVersion($task) { foreach ($copy as $file) { $fileAndVersion[] = StringHelper::explode($file, " ", true, true); } - $branch = $task->branch == 'trunk' ? $task->branch + // 兼容无trunk、无branches、无tags下为空 + $branch = ($task->branch == 'trunk' || $task->branch == '') + ? $task->branch : ($this->getConfig()->repo_mode == Project::REPO_BRANCH ? 'branches/' : 'tags/') . $task->branch; // 先更新 $versionSvnDir = sprintf('%s-svn', rtrim(Project::getDeployWorkspace($task->link_id), '/')); @@ -75,26 +77,34 @@ public function updateToVersion($task) { * @return array */ public function getBranchList() { + // 更新 + $this->updateRepo(); $list = []; $branchDir = 'tags'; if ($this->getConfig()->repo_mode == Project::REPO_BRANCH) { - $list[] = [ - 'id' => 'trunk', - 'message' => 'trunk', - ]; $branchDir = 'branches'; + $trunkDir = sprintf("%s/trunk", rtrim(Project::getDeployFromDir(), '/')); + + if (file_exists($trunkDir)) { + $list[] = [ + 'id' => 'trunk', + 'message' => 'trunk', + ]; + } else { + $list[] = [ + 'id' => '', + 'message' => \yii::t('w', 'default trunk'), + ]; + } } - $svnType = sprintf("%s/%s", rtrim(Project::getDeployFromDir(), '/'), $branchDir); - - // 更新 - $this->updateRepo(); + $branchDir = sprintf("%s/%s", rtrim(Project::getDeployFromDir(), '/'), $branchDir); // 如果不存在branches目录,则跳过查找其它分支 - if (!file_exists($svnType)) { + if (!file_exists($branchDir)) { return $list; } - $branches = new \DirectoryIterator($svnType); + $branches = new \DirectoryIterator($branchDir); foreach ($branches as $branch) { $name = $branch->__toString(); if ($branch->isDot() || $branch->isFile()) continue; @@ -113,7 +123,7 @@ public function getBranchList() { * * @return array */ - public function getCommitList($branch = 'master', $count = 30) { + public function getCommitList($branch = 'trunk', $count = 30) { // 先更新 $destination = Project::getDeployFromDir(); $this->updateRepo($branch, $destination); @@ -219,7 +229,8 @@ public static function formatXmlLog($xmlString) { public static function getBranchDir($branch, $tag = false) { $svnDir = Project::getDeployFromDir(); - $branchDir = $branch == 'trunk' && !$tag + // 兼容无trunk、无branches、无tags下为空 + $branchDir = ($branch == '' || $branch == 'trunk') && !$tag ? $branch : ($tag ? 'tags/'.$branch : 'branches/'.$branch); return sprintf('%s/%s', $svnDir, $branchDir); diff --git a/messages/en/w.php b/messages/en/w.php index 1169cb4c..2a4a62b4 100644 --- a/messages/en/w.php +++ b/messages/en/w.php @@ -25,6 +25,7 @@ 'conf_level_2' => 'Pre-Release', 'conf_level_3' => 'Production', + 'default trunk' => 'default no trunk', 'conf_status_0' => 'Invalid', 'conf_status_1' => 'Valid', 'conf_audit_0' => 'Yes', diff --git a/messages/zh/w.php b/messages/zh/w.php index 148c43cd..61dfba7e 100644 --- a/messages/zh/w.php +++ b/messages/zh/w.php @@ -25,6 +25,7 @@ 'conf_level_2' => '预发布环境', 'conf_level_3' => '线上环境', + 'default trunk' => '默认无trunk', 'conf_status_0' => '无效', 'conf_status_1' => '有效', 'conf_audit_0' => '是', diff --git a/views/task/submit-svn.php b/views/task/submit-svn.php index 97c25b79..6a314711 100644 --- a/views/task/submit-svn.php +++ b/views/task/submit-svn.php @@ -170,7 +170,7 @@ function getChangeFiles(projectId, branch, start, end) { getBranchList(); // 页面加载完默认拉取trunk if ($('#branch').val()) { - getCommitList(); + // getCommitList(); }