Skip to content

Commit eaf414a

Browse files
committed
chore: rework error message
Change-Id: Ia2f65f2b8f2f334a4841fce1e43b60919e9184f0
1 parent 17ef5b2 commit eaf414a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

mergify_cli/stack/push.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def format_pull_description(
6565

6666
# TODO(charly): fix code to conform to linter (number of arguments, local
6767
# variables, statements, positional arguments, branches)
68-
async def stack_push( # noqa: PLR0912, PLR0913, PLR0915, PLR0917
68+
async def stack_push( # noqa: PLR0912, PLR0913, PLR0915, PLR0917, PLR0914
6969
github_server: str,
7070
token: str,
7171
skip_rebase: bool,
@@ -105,7 +105,14 @@ async def stack_push( # noqa: PLR0912, PLR0913, PLR0915, PLR0917
105105
)
106106

107107
if base_branch == dest_branch:
108-
console.log("[red] base branch and destination branch are the same [/]")
108+
remote_url = await utils.git("remote", "get-url", remote)
109+
console.print(
110+
f"Your local branch `{dest_branch}` targets itself: `{remote}/{base_branch}` (at {remote_url}@{base_branch}).\n"
111+
f"You should either fix the target branch or rename your local branch.\n\n"
112+
f"* To fix the target branch: `git branch {dest_branch} --set-upstream-to={remote}/main>\n",
113+
f"* To rename your local branch: `git branch -M {dest_branch} new-branch-name`",
114+
style="red",
115+
)
109116
sys.exit(1)
110117

111118
stack_prefix = f"{branch_prefix}/{dest_branch}" if branch_prefix else dest_branch

mergify_cli/tests/stack/test_push.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,12 @@ async def test_stack_on_destination_branch_raises_an_error(
487487
) -> None:
488488
respx_mock.get("/user").respond(200, json={"login": "author"})
489489
git_mock.mock("rev-parse", "--abbrev-ref", "HEAD", output="main")
490+
git_mock.mock(
491+
"remote",
492+
"get-url",
493+
"origin",
494+
output="https://github.com/foo/bar.git",
495+
)
490496

491497
with pytest.raises(SystemExit, match="1"):
492498
await push.stack_push(

0 commit comments

Comments
 (0)