shadow-repos: check if path to shadow repo existing before trying to call SCM object.

- sometimes cleanups of shadow repos can occur. We should fail only if shadow repo path
is there, and we can create a repo object from it.
This commit is contained in:
Marcin Kuzminski 2018-06-17 12:55:27 +02:00
parent e0b621ed56
commit 5df4647bd0
2 changed files with 7 additions and 4 deletions

View file

@ -433,12 +433,14 @@ class RepoPullRequestsView(RepoAppView, DataGridAppView):
source_scm = source_repo.scm_instance()
target_scm = target_repo.scm_instance()
# try first shadow repo, fallback to regular repo
shadow_scm = None
try:
commits_source_repo = pull_request_latest.get_shadow_repo()
shadow_scm = pull_request_latest.get_shadow_repo()
except Exception:
log.debug('Failed to get shadow repo', exc_info=True)
commits_source_repo = source_scm
# try first the existing source_repo, and then shadow
# repo if we can obtain one
commits_source_repo = source_scm or shadow_scm
c.commits_source_repo = commits_source_repo
c.ancestor = None # set it to None, to hide it from PR view

View file

@ -3763,7 +3763,8 @@ class PullRequest(Base, _PullRequestBase):
vcs_obj = self.target_repo.scm_instance()
shadow_repository_path = vcs_obj._get_shadow_repository_path(
workspace_id)
return vcs_obj._get_shadow_instance(shadow_repository_path)
if os.path.isdir(shadow_repository_path):
return vcs_obj._get_shadow_instance(shadow_repository_path)
class PullRequestVersion(Base, _PullRequestBase):