Skip to content

Commit

Permalink
chore: on commit not in branch error show repo name
Browse files Browse the repository at this point in the history
When reporting that a commit is not in the requested branch, also print
the name of the repo. This helps the user to fix the issue.

While fixing this, we also align the quoting of the repository name in
the error messages.

Signed-off-by: Felix Moessbauer <[email protected]>
Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
fmoessbauer authored and jan-kiszka committed Mar 5, 2024
1 parent f2237e0 commit 01452f4
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions kas/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def factory(name, repo_config, repo_defaults, repo_fallback_path,
if refspec is None:
commit = repo_overrides.get('commit', commit)
if commit and get_context().update:
logging.warning(f'Update of {name} requested, but repo is '
logging.warning(f'Update of "{name}" requested, but repo is '
'pinned to a fixed commit. Not updating.')
else:
if name not in Repo.__legacy_refspec_warned__:
Expand All @@ -202,8 +202,9 @@ def factory(name, repo_config, repo_defaults, repo_fallback_path,
name)
Repo.__legacy_refspec_warned__.append(name)
if commit is not None or tag is not None or branch is not None:
raise RepoRefError('Unsupported mixture of legacy refspec and '
'commit/tag/branch for repository "{name}"')
raise RepoRefError(
'Unsupported mixture of legacy refspec and '
f'commit/tag/branch for repository "{name}"')
refspec = repo_overrides.get('commit', refspec)
if tag and not commit:
if name not in Repo.__no_commit_tag_warned__:
Expand Down Expand Up @@ -369,7 +370,7 @@ def checkout(self):
fail=False)
if retc:
raise RepoRefError(f'Tag "{self.tag}" cannot be found '
f'in repository {self.name}')
f'in repository "{self.name}"')

if self.commit and output.strip() != self.commit:
# Ensure provided commit and tag match
Expand All @@ -385,14 +386,15 @@ def checkout(self):
if retc:
raise RepoRefError(
f'Branch "{self.branch}" cannot be found '
f'in repository {self.name}')
f'in repository "{self.name}"')
if self.commit:
(_, output) = run_cmd(self.branch_contains_ref(),
cwd=self.path,
fail=False)
if not output.strip():
raise RepoRefError(
f'Branch "{self.branch}" does not contain '
f'Branch "{self.branch}" in '
f'repository "{self.name}" does not contain '
f'commit "{self.commit}"')

desired_ref = self.commit or output.strip()
Expand Down

0 comments on commit 01452f4

Please sign in to comment.