Skip to content

Commit

Permalink
Make git{hub,lab} restack-{pr,mr} first retarget, then push
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelLipski committed Apr 19, 2024
1 parent 3380825 commit ace2593
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## New in git-machete 3.25.1

- fixed: `git machete git{hub,lab} restack-{pr,mr}` now first retargets, then pushes (so that certain CIs see the correct base branch in env vars)

## New in git-machete 3.25.0

- added: GitLab support via `git machete gitlab` (first suggested by @mikeynap, partly contributed by @max-nicholson)
Expand Down
5 changes: 3 additions & 2 deletions git_machete/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2268,6 +2268,9 @@ def restack_pull_request(self, spec: CodeHostingSpec) -> None:
if converted_to_draft:
print(f'{pr.display_text()} has been temporarily marked as draft')

# Note that retarget should happen BEFORE push, see issue #1222
self.retarget_pr(spec, head, ignore_if_missing=False)

if s == SyncToRemoteStatuses.AHEAD_OF_REMOTE:
assert remote is not None
self.__handle_ahead_state(
Expand Down Expand Up @@ -2303,8 +2306,6 @@ def restack_pull_request(self, spec: CodeHostingSpec) -> None:
opt_no_detect_squash_merges=False)
self.__print_new_line(False)

self.retarget_pr(spec, head, ignore_if_missing=False)

if converted_to_draft:
code_hosting_client.set_draft_status_of_pull_request(prs[0].number, target_draft_status=False)
print(f'{pr.display_text()} has been marked as ready for review again')
Expand Down
16 changes: 8 additions & 8 deletions tests/test_github_restack_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ def test_github_restack_pr_branch_untracked(self, mocker: MockerFixture) -> None
assert_success(
['github', 'restack-pr'],
"""
Base branch of PR #14 has been switched to master
Pushing untracked branch feature_1 to origin...
master (untracked)
|
o-feature_1 *
o-feature_1 * PR #14 (some_other_user)
Base branch of PR #14 has been switched to master
"""
)
pr = github_api_state.get_pull_by_number(14)
Expand Down Expand Up @@ -149,15 +149,15 @@ def test_github_restack_pr_branch_diverged_and_newer(self, mocker: MockerFixture
['github', 'restack-pr'],
"""
PR #15 has been temporarily marked as draft
Base branch of PR #15 has been switched to master
Description of PR #15 has been updated
Branch feature diverged from (and has newer commits than) its remote counterpart origin/feature.
Pushing feature with force-with-lease to origin...
master (untracked)
|
o-feature *
o-feature * PR #15 (some_other_user)
Base branch of PR #15 has been switched to master
Description of PR #15 has been updated
PR #15 has been marked as ready for review again
"""
)
Expand Down Expand Up @@ -192,14 +192,14 @@ def test_github_restack_pr_branch_ahead(self, mocker: MockerFixture) -> None:
['github', 'restack-pr'],
"""
PR #15 has been temporarily marked as draft
Base branch of PR #15 has been switched to master
Description of PR #15 has been updated
Pushing feature to origin...
master (untracked)
|
o-feature *
o-feature * PR #15 (some_other_user)
Base branch of PR #15 has been switched to master
Description of PR #15 has been updated
PR #15 has been marked as ready for review again
"""
)
Expand Down
16 changes: 8 additions & 8 deletions tests/test_gitlab_restack_mr.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ def test_gitlab_restack_mr_branch_untracked(self, mocker: MockerFixture) -> None
assert_success(
['gitlab', 'restack-mr'],
"""
Target branch of MR !14 has been switched to master
Pushing untracked branch feature_1 to origin...
master (untracked)
|
o-feature_1 *
o-feature_1 * MR !14 (some_other_user)
Target branch of MR !14 has been switched to master
"""
)
mr = gitlab_api_state.get_pull_by_number(14)
Expand Down Expand Up @@ -152,15 +152,15 @@ def test_gitlab_restack_mr_branch_diverged_and_newer(self, mocker: MockerFixture
['gitlab', 'restack-mr'],
"""
MR !15 has been temporarily marked as draft
Target branch of MR !15 has been switched to master
Description of MR !15 has been updated
Branch feature diverged from (and has newer commits than) its remote counterpart origin/feature.
Pushing feature with force-with-lease to origin...
master (untracked)
|
o-feature *
o-feature * MR !15 (some_other_user)
Target branch of MR !15 has been switched to master
Description of MR !15 has been updated
MR !15 has been marked as ready for review again
"""
)
Expand Down Expand Up @@ -196,14 +196,14 @@ def test_gitlab_restack_mr_branch_ahead(self, mocker: MockerFixture) -> None:
['gitlab', 'restack-mr'],
"""
MR !15 has been temporarily marked as draft
Target branch of MR !15 has been switched to master
Description of MR !15 has been updated
Pushing feature to origin...
master (untracked)
|
o-feature *
o-feature * MR !15 (some_other_user)
Target branch of MR !15 has been switched to master
Description of MR !15 has been updated
MR !15 has been marked as ready for review again
"""
)
Expand Down

0 comments on commit ace2593

Please sign in to comment.