Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions mergify_cli/stack/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def format_pull_description(

# TODO(charly): fix code to conform to linter (number of arguments, local
# variables, statements, positional arguments, branches)
async def stack_push( # noqa: PLR0912, PLR0913, PLR0915, PLR0917
async def stack_push( # noqa: PLR0912, PLR0913, PLR0915, PLR0917, PLR0914
github_server: str,
token: str,
skip_rebase: bool,
Expand Down Expand Up @@ -105,7 +105,14 @@ async def stack_push( # noqa: PLR0912, PLR0913, PLR0915, PLR0917
)

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

stack_prefix = f"{branch_prefix}/{dest_branch}" if branch_prefix else dest_branch
Expand Down
6 changes: 6 additions & 0 deletions mergify_cli/tests/stack/test_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,12 @@ async def test_stack_on_destination_branch_raises_an_error(
) -> None:
respx_mock.get("/user").respond(200, json={"login": "author"})
git_mock.mock("rev-parse", "--abbrev-ref", "HEAD", output="main")
git_mock.mock(
"remote",
"get-url",
"origin",
output="https://github.com/foo/bar.git",
)

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