* Fix bug #46141, adjust repo connected check logic.

This commit is contained in:
caoyanyi
2024-03-11 09:55:04 +08:00
parent d5d944ba36
commit 13763b732d
2 changed files with 21 additions and 7 deletions
+2 -7
View File
@@ -417,7 +417,7 @@ class repo extends control
$oldRevision = isset($this->post->revision[1]) ? $this->post->revision[1] : '';
$newRevision = isset($this->post->revision[0]) ? $this->post->revision[0] : '';
$this->locate($this->repo->createLink('diff', "repoID=$repoID&objectID=$objectID&entry=" . $this->repo->encodePath($path) . "&oldrevision=$oldRevision&newRevision=$newRevision"));
return $this->locate($this->repo->createLink('diff', "repoID=$repoID&objectID=$objectID&entry=" . $this->repo->encodePath($path) . "&oldrevision=$oldRevision&newRevision=$newRevision"));
}
/* Set menu and session. */
@@ -427,11 +427,7 @@ class repo extends control
/* Get repo and synchronous commit. */
$repo = $this->repo->getByID($repoID);
if($repo->SCM == 'Git' && !is_dir($repo->path)) return $this->sendError(sprintf($this->lang->repo->error->notFound, $repo->name, $repo->path), $this->repo->createLink('maintain'));
if($repo && substr($repo->path, 0, 4) == 'http')
{
if(!$this->loadModel('admin')->checkInternet($repo->path)) return $this->sendError($this->lang->repo->error->connect, true);
}
if($this->repoZen->checkRepoInternet($repo)) return $this->sendError($this->lang->repo->error->connect, true);
if(!$repo->synced) return $this->locate($this->repo->createLink('showSyncCommit', "repoID=$repoID&objectID=$objectID"));
/* Set branch or tag for git. */
@@ -478,7 +474,6 @@ class repo extends control
$this->view->cloneUrl = $this->repo->getCloneUrl($repo);
$this->view->repoPairs = $this->repo->getRepoPairs($this->app->tab, $objectID);
$this->view->branchOrTag = $branchOrTag;
$this->display();
}
+19
View File
@@ -1578,4 +1578,23 @@ class repoZen extends repo
return $tree;
}
/**
* 检查代码库是否能正常访问。
* Check repo connected.
*
* @param object $repo
* @access protected
* @return bool
*/
protected function checkRepoInternet(object $repo): bool
{
if(!$repo) return false;
$repoUrl = '';
if(empty($repoUrl) && isset($repo->path) && substr($repo->path, 0, 4) == 'http') $repoUrl = $repo->path;
if(empty($repoUrl) && isset($repo->client) && substr($repo->client, 0, 4) == 'http') $repoUrl = $repo->client;
if(empty($repoUrl) && isset($repo->apiPath) && substr($repo->apiPath, 0, 4) == 'http') $repoUrl = $repo->apiPath;
return $repoUrl && !$this->loadModel('admin')->checkInternet($repoUrl);
}
}