From 91e680de2fc413bee6e899ddb33c1862e6a8137c Mon Sep 17 00:00:00 2001 From: aaronchen2k <462826@qq.com> Date: Mon, 13 Jan 2020 11:09:37 +0800 Subject: [PATCH] sync repo by using a page button --- module/ci/control.php | 29 +++++++++++++++++++++---- module/ci/lang/zh-cn.php | 1 + module/ci/view/browserepo.html.php | 2 ++ module/ci/view/showsynccomment.html.php | 6 ++++- module/git/model.php | 14 +++++++----- 5 files changed, 42 insertions(+), 10 deletions(-) diff --git a/module/ci/control.php b/module/ci/control.php index ffdba75c1b..0a2b88277f 100644 --- a/module/ci/control.php +++ b/module/ci/control.php @@ -403,9 +403,9 @@ class ci extends control $repo = $this->ci->getRepoByID($repoID); if($_POST) { - $needSync = $this->ci->updateRepo($repoID); + $noNeedSync = $this->ci->updateRepo($repoID); if(dao::isError()) die(js::error(dao::getError())); - if(!$needSync) + if(!$noNeedSync) { $link = $this->ci->createLink('showSyncComment', "repoID=$repoID"); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $link)); @@ -463,6 +463,21 @@ class ci extends control $this->display(); } + /** + * sync repo from remote. + * + * @param int $repoID + * @access public + * @return void + */ + public function syncRepo($repoID = 0) + { + $this->dao->update(TABLE_REPO)->set('synced')->eq(0)->where('id')->eq($repoID)->exec(); + + $link = $this->ci->createLink('showSyncComment', "repoID=$repoID&needPull=true"); + $this->send(array('result' => 'success', 'locate' => $link)); + } + /** * watch branch. * @@ -486,7 +501,7 @@ class ci extends control * @access public * @return void */ - public function showSyncComment($repoID = 0) + public function showSyncComment($repoID = 0, $needPull = false) { if($repoID == 0) $repoID = $this->session->repoID; @@ -496,6 +511,7 @@ class ci extends control $latestInDB = $this->ci->getLatestComment($repoID, ); $this->view->version = $latestInDB ? (int)$latestInDB->commit : 1; $this->view->repoID = $repoID; + $this->view->needPull = $needPull; $this->display(); } @@ -507,10 +523,15 @@ class ci extends control * @access public * @return void */ - public function ajaxSyncComment($repoID = 0, $type = 'batch') + public function ajaxSyncComment($repoID = 0, $type = 'batch', $needPull = false) { set_time_limit(0); $repo = $this->ci->getRepoByID($repoID); + + if ($needPull) { + $this->loadModel('git')->pull($repo); + } + if(empty($repo)) die(); if($repo->synced) die('finish'); diff --git a/module/ci/lang/zh-cn.php b/module/ci/lang/zh-cn.php index ac621283a1..d0136cd008 100644 --- a/module/ci/lang/zh-cn.php +++ b/module/ci/lang/zh-cn.php @@ -96,6 +96,7 @@ $lang->repo->create = '添加代码库'; $lang->repo->edit = '编辑代码库'; $lang->repo->delete = '删除代码库'; $lang->repo->confirmDelete = '确认删除该代码库吗?'; +$lang->repo->browseBranch = '查看分支'; $lang->repo->id = 'ID'; $lang->repo->name = '名称'; diff --git a/module/ci/view/browserepo.html.php b/module/ci/view/browserepo.html.php index 7d077d195e..0ea4bc97db 100644 --- a/module/ci/view/browserepo.html.php +++ b/module/ci/view/browserepo.html.php @@ -40,6 +40,8 @@