mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-10 14:56:14 +01:00
Fix GitStore to error out properly if there is no 'origin' remote in the git repo
This commit is contained in:
parent
6eb9c4b186
commit
5a67bd3376
@ -13,5 +13,5 @@ Scenario: Run `osc addcontainers`
|
||||
Then the exit code is 1
|
||||
And stderr is
|
||||
"""
|
||||
Directory '{context.osc.temp}/test:factory' is not a working copy of a package
|
||||
Directory '{context.osc.temp}/test:factory' is not an OBS SCM working copy of a package
|
||||
"""
|
||||
|
@ -13,5 +13,5 @@ Scenario: Run `osc develproject`
|
||||
Then the exit code is 1
|
||||
And stderr is
|
||||
"""
|
||||
Directory '{context.osc.temp}/test:factory' is not a working copy of a package
|
||||
Directory '{context.osc.temp}/test:factory' is not an OBS SCM working copy of a package
|
||||
"""
|
||||
|
@ -13,5 +13,5 @@ Scenario: Run `osc setdevelproject <devel_project>`
|
||||
Then the exit code is 1
|
||||
And stderr is
|
||||
"""
|
||||
Directory '{context.osc.temp}/test:factory' is not a working copy of a package
|
||||
Directory '{context.osc.temp}/test:factory' is not an OBS SCM working copy of a package
|
||||
"""
|
||||
|
@ -13,5 +13,5 @@ Scenario: Run `osc showlinked`
|
||||
Then the exit code is 1
|
||||
And stderr is
|
||||
"""
|
||||
Directory '{context.osc.temp}/test:factory' is not a working copy of a package
|
||||
Directory '{context.osc.temp}/test:factory' is not an OBS SCM working copy of a package
|
||||
"""
|
||||
|
@ -38,7 +38,11 @@ class GitStore:
|
||||
self._project = None
|
||||
|
||||
if check and not any([self.is_project, self.is_package]):
|
||||
msg = f"Directory '{self.path}' is not a GIT working copy"
|
||||
msg = f"Directory '{self.path}' is not a Git SCM working copy"
|
||||
raise oscerr.NoWorkingCopy(msg)
|
||||
|
||||
if check and not self.scmurl:
|
||||
msg = f"Directory '{self.path}' is a Git SCM repo that lacks the 'origin' remote"
|
||||
raise oscerr.NoWorkingCopy(msg)
|
||||
|
||||
# TODO: decide if we need explicit 'git lfs pull' or not
|
||||
@ -46,12 +50,12 @@ class GitStore:
|
||||
|
||||
def assert_is_project(self):
|
||||
if not self.is_project:
|
||||
msg = f"Directory '{self.path}' is not a GIT working copy of a project"
|
||||
msg = f"Directory '{self.path}' is not a Git SCM working copy of a project"
|
||||
raise oscerr.NoWorkingCopy(msg)
|
||||
|
||||
def assert_is_package(self):
|
||||
if not self.is_package:
|
||||
msg = f"Directory '{self.path}' is not a GIT working copy of a package"
|
||||
msg = f"Directory '{self.path}' is not a Git SCM working copy of a package"
|
||||
raise oscerr.NoWorkingCopy(msg)
|
||||
|
||||
def _run_git(self, args):
|
||||
@ -148,4 +152,7 @@ class GitStore:
|
||||
|
||||
@property
|
||||
def scmurl(self):
|
||||
return self._run_git(["remote", "get-url", "origin"])
|
||||
try:
|
||||
return self._run_git(["remote", "get-url", "origin"])
|
||||
except subprocess.CalledProcessError:
|
||||
return None
|
||||
|
29
osc/store.py
29
osc/store.py
@ -40,7 +40,7 @@ class Store:
|
||||
self.is_package = self.exists("_project") and self.exists("_package")
|
||||
|
||||
if check and not any([self.is_project, self.is_package]):
|
||||
msg = f"Directory '{self.path}' is not a working copy"
|
||||
msg = f"Directory '{self.path}' is not an OBS SCM working copy"
|
||||
raise oscerr.NoWorkingCopy(msg)
|
||||
|
||||
def __contains__(self, fn):
|
||||
@ -52,12 +52,12 @@ class Store:
|
||||
|
||||
def assert_is_project(self):
|
||||
if not self.is_project:
|
||||
msg = f"Directory '{self.path}' is not a working copy of a project"
|
||||
msg = f"Directory '{self.path}' is not an OBS SCM working copy of a project"
|
||||
raise oscerr.NoWorkingCopy(msg)
|
||||
|
||||
def assert_is_package(self):
|
||||
if not self.is_package:
|
||||
msg = f"Directory '{self.path}' is not a working copy of a package"
|
||||
msg = f"Directory '{self.path}' is not an OBS SCM working copy of a package"
|
||||
raise oscerr.NoWorkingCopy(msg)
|
||||
|
||||
def get_path(self, fn, subdir=None):
|
||||
@ -317,14 +317,19 @@ def get_store(path, check=True, print_warnings=False):
|
||||
- Store for OBS SCM
|
||||
- GitStore for Git SCM
|
||||
"""
|
||||
try:
|
||||
|
||||
# if there are '.osc' and '.git' directories next to each other, '.osc' takes preference
|
||||
if os.path.exists(os.path.join(path, ".osc")):
|
||||
store = Store(path, check)
|
||||
except oscerr.NoWorkingCopy as ex:
|
||||
try:
|
||||
store = git_scm.GitStore(path, check)
|
||||
if print_warnings:
|
||||
git_scm.warn_experimental()
|
||||
except oscerr.NoWorkingCopy as ex_git:
|
||||
# raise the original exception, do not inform that we've tried git working copy
|
||||
raise ex from None
|
||||
elif os.path.exists(os.path.join(path, ".git")):
|
||||
store = git_scm.GitStore(path, check)
|
||||
if print_warnings:
|
||||
git_scm.warn_experimental()
|
||||
else:
|
||||
store = None
|
||||
|
||||
if not store:
|
||||
msg = f"Directory '{path}' is not a working copy"
|
||||
raise oscerr.NoWorkingCopy(msg)
|
||||
|
||||
return store
|
||||
|
Loading…
Reference in New Issue
Block a user