Skip to content

Commit

Permalink
Merge pull request #1392 from dmach/git-no-remote
Browse files Browse the repository at this point in the history
Fix GitStore to error out properly if there is no 'origin' remote in the git repo
  • Loading branch information
dmach committed Aug 28, 2023
2 parents a01e6da + 5a67bd3 commit 7ab3a64
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion behave/features/addcontainers-prjcheckout.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
2 changes: 1 addition & 1 deletion behave/features/develproject-prjcheckout.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
2 changes: 1 addition & 1 deletion behave/features/setdevelproject-prjcheckout.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
2 changes: 1 addition & 1 deletion behave/features/showlinked-prjcheckout.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
8 changes: 0 additions & 8 deletions osc/babysitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ def run(prg, argv=None):
print(e, file=sys.stderr)
except oscerr.NoWorkingCopy as e:
print(e, file=sys.stderr)
if os.path.isdir('.git'):
print("Current directory looks like git.", file=sys.stderr)
if os.path.isdir('.hg'):
print("Current directory looks like mercurial.", file=sys.stderr)
if os.path.isdir('.svn'):
print("Current directory looks like svn.", file=sys.stderr)
if os.path.isdir('CVS'):
print("Current directory looks like cvs.", file=sys.stderr)
except HTTPError as e:
print('Server returned an error:', e, file=sys.stderr)
if hasattr(e, 'osc_msg'):
Expand Down
15 changes: 11 additions & 4 deletions osc/git_scm/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,24 @@ def __init__(self, path, check=True):
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
# self._run_git(["lfs", "pull"])

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):
Expand Down Expand Up @@ -148,4 +152,7 @@ def last_buildroot(self, value):

@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 changes: 17 additions & 12 deletions osc/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, path, check=True):
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):
Expand All @@ -52,12 +52,12 @@ def __iter__(self):

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):
Expand Down Expand Up @@ -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

0 comments on commit 7ab3a64

Please sign in to comment.