Skip to content

Commit

Permalink
Improve remote error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
simahawk committed Sep 8, 2023
1 parent 9348907 commit 27b0ba1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion oca_port/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def _prepare_repos(self):
if self.repo.is_dirty(untracked_files=True):
raise ValueError("changes not committed detected in this repository.")
if self.destination and self.destination.remote not in self.repo.remotes:
raise ForkValueError(self.repo_name, self.destination.remote)
raise ForkValueError(self.destination)
# Transform branch strings to Branch objects
try:
self.from_branch = self._prepare_branch(self.source)
Expand Down
17 changes: 9 additions & 8 deletions oca_port/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ def main(
cli=True,
)
except ForkValueError as exc:
error_msg = prepare_remote_error_msg(*exc.args)
error_msg = prepare_remote_error_msg(exc.entity)
error_msg += (
"\n\nYou can change the GitHub organization with the "
f"{bc.DIM}--user-org{bc.END} option."
)
raise click.ClickException(error_msg) from exc
except RemoteBranchValueError as exc:
error_msg = prepare_remote_error_msg(*exc.args)
error_msg = prepare_remote_error_msg(exc.entity)
raise click.ClickException(error_msg) from exc
except ValueError as exc:
raise click.ClickException(exc) from exc
Expand All @@ -180,17 +180,18 @@ def main(
raise click.ClickException(exc) from exc


def prepare_remote_error_msg(repo_name, remote):
def prepare_remote_error_msg(entity):
return (
f"No remote {bc.FAIL}{remote}{bc.END} in the current repository.\n"
f"No remote for {bc.FAIL}{entity._kind} {entity._ref}{bc.END} "
"in the current repository.\n"
"To add it:\n"
"\t# This mode requires an SSH key in the GitHub account\n"
f"\t{bc.DIM}$ git remote add {remote} "
f"git@github.com:{remote}/{repo_name}.git{bc.END}\n"
f"\t{bc.DIM}$ git remote add {entity.org} "
f"git@github.com:{entity.org}/{entity.repo}.git{bc.END}\n"
" Or:\n"
"\t# This will require to enter user/password each time\n"
f"\t{bc.DIM}$ git remote add {remote} "
f"https://github.com/{remote}/{repo_name}.git{bc.END}"
f"\t{bc.DIM}$ git remote add {entity.org} "
f"https://github.com/{entity.org}/{entity.repo}.git{bc.END}"
)


Expand Down
4 changes: 3 additions & 1 deletion oca_port/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@


class ForkValueError(ValueError):
pass
def __init__(self, entity):
super().__init__(entity._ref)
self.entity = entity


class RemoteBranchValueError(ValueError):
Expand Down

0 comments on commit 27b0ba1

Please sign in to comment.