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
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## New in git-machete 3.45.1

- fixed: `git machete traverse --sync-github-prs`/`--sync-gitlab-mrs` no longer offers to create a PR/MR for a branch annotated with `push=no`
- fixed: `git machete discover` preserves full annotations on rediscovered branches, rather than only their traversal qualifiers (contributed by @be-student)
- fixed: branch layout files are now always read and written as UTF-8 rather than the process locale encoding, so annotations with non-ASCII characters no longer break on Windows

Expand Down
3 changes: 2 additions & 1 deletion docs/man/git-machete.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion docs/source/cli/traverse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ For each branch, the command performs the following actions:

* if ``-H``/``--sync-github-prs`` or ``-L``/``--sync-gitlab-mrs`` option is present:

- asks the user whether to **create** a PR/MR for the given branch if it doesn't exist yet,
- asks the user whether to **create** a PR/MR for the given branch if it doesn't exist yet (unless the branch is annotated with ``push=no``),

- asks the user whether to **retarget** the PR/MR if it exists for the given branch,
and its base/target branch in GitHub/GitLab is different than the upstream in machete file
Expand All @@ -69,6 +69,7 @@ Unlike with ``git rebase`` or ``git cherry-pick``, there is no special ``--conti

The rebase, push and slide-out behaviors of ``traverse`` can also be customized for each branch separately using *branch qualifiers*.
There are ``push=no``, ``rebase=no`` and ``slide-out=no`` qualifiers that can be used to opt out of default behavior (rebasing, pushing and sliding the branch out).
``push=no`` also skips creating a PR/MR under ``--sync-github-prs``/``--sync-gitlab-mrs``.
The qualifier can appear anywhere in the annotation, but needs to be separated by a whitespace from any other character, as in: ``some_annotation_text rebase=no push=no slide-out=no``.
Qualifiers can only be overwritten by manually editing ``.git/machete`` file or modifying it with ``git machete e[dit]``, or by updating annotations with ``git machete anno``.
Example machete file with branch qualifiers:
Expand Down
3 changes: 2 additions & 1 deletion git_machete/client/traverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ def traverse(
if parent:
prs = [_pr for _pr in self._get_all_open_prs() if _pr.head == branch]
if not prs:
needs_create_pr = True
if branch_anno is None or branch_anno.qualifiers.push:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split for the sake of coverage

needs_create_pr = True

use_merge = opt_merge or (branch_anno is not None and branch_anno.qualifiers.update_with_merge)

Expand Down
3 changes: 2 additions & 1 deletion git_machete/generated_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1686,7 +1686,7 @@

* if `-H`/`--sync-github-prs` or `-L`/`--sync-gitlab-mrs` option is present:

- asks the user whether to <b>create</b> a PR/MR for the given branch if it doesn't exist yet,
- asks the user whether to <b>create</b> a PR/MR for the given branch if it doesn't exist yet (unless the branch is annotated with `push=no`),

- asks the user whether to <b>retarget</b> the PR/MR if it exists for the given branch,
and its base/target branch in GitHub/GitLab is different than the upstream in machete file
Expand All @@ -1705,6 +1705,7 @@

The rebase, push and slide-out behaviors of `traverse` can also be customized for each branch separately using branch qualifiers.
There are `push=no`, `rebase=no` and `slide-out=no` qualifiers that can be used to opt out of default behavior (rebasing, pushing and sliding the branch out).
`push=no` also skips creating a PR/MR under `--sync-github-prs`/`--sync-gitlab-mrs`.
The qualifier can appear anywhere in the annotation, but needs to be separated by a whitespace from any other character, as in: `some_annotation_text rebase=no push=no slide-out=no`.
Qualifiers can only be overwritten by manually editing `.git/machete` file or modifying it with `git machete e[dit]`, or by updating annotations with `git machete anno`.
Example machete file with branch qualifiers:
Expand Down
64 changes: 64 additions & 0 deletions tests/test_traverse_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,67 @@ def test_traverse_sync_create_github_prs(self, mocker: MockerFixture) -> None:
Reached branch drop-constraint which has no successor; nothing left to update
"""
)

def test_traverse_sync_create_github_prs_skips_push_no(self, mocker: MockerFixture) -> None:
self.patch_symbol(mocker, 'git_machete.code_hosting.OrganizationAndRepository.from_url', mock_from_url)
self.patch_symbol(mocker, 'git_machete.github.GitHubToken.for_domain', mock_github_token_for_domain_fake)
self.patch_symbol(mocker, 'urllib.request.urlopen', mock_urlopen(MockGitHubAPIState.with_prs()))

create_repo_with_remote()
new_branch("develop")
commit()
push()
new_branch("someone-elses-branch")
commit()
push()
check_out("develop")
new_branch("annotated-ok")
commit()
push()
check_out("develop")
new_branch("my-branch")
commit()
push()

body: str = \
"""
develop
someone-elses-branch rebase=no push=no
annotated-ok WIP
my-branch
"""
rewrite_branch_layout_file(body)
check_out("develop")

self.patch_symbol(mocker, 'builtins.input', mock_input_returning("n", "q"))
assert_success(
["traverse", "--sync-github-prs"],
"""
Checking for open GitHub PRs... OK
Checking out annotated-ok... OK

develop
|
o-someone-elses-branch rebase=no push=no
|
o-annotated-ok * WIP
|
o-my-branch

Branch annotated-ok does not have a PR in GitHub.
Create a PR from annotated-ok to develop? (y, d[raft], N, q, yq)

Checking out my-branch... OK

develop
|
o-someone-elses-branch rebase=no push=no
|
o-annotated-ok WIP
|
o-my-branch *

Branch my-branch does not have a PR in GitHub.
Create a PR from my-branch to develop? (y, d[raft], N, q, yq)
"""
)
64 changes: 64 additions & 0 deletions tests/test_traverse_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,67 @@ def test_traverse_sync_gitlab_mrs(self, mocker: MockerFixture) -> None:
Retarget MR !2 to allow-ownership-link? (y, N, q, yq)
Switching target branch of MR !2 to allow-ownership-link... OK
""")

def test_traverse_sync_create_gitlab_mrs_skips_push_no(self, mocker: MockerFixture) -> None:
self.patch_symbol(mocker, 'git_machete.code_hosting.OrganizationAndRepository.from_url', mock_from_url)
self.patch_symbol(mocker, 'git_machete.gitlab.GitLabToken.for_domain', mock_gitlab_token_for_domain_fake)
self.patch_symbol(mocker, 'urllib.request.urlopen', mock_urlopen(MockGitLabAPIState.with_mrs()))

create_repo_with_remote()
new_branch("develop")
commit()
push()
new_branch("someone-elses-branch")
commit()
push()
check_out("develop")
new_branch("annotated-ok")
commit()
push()
check_out("develop")
new_branch("my-branch")
commit()
push()

body: str = \
"""
develop
someone-elses-branch rebase=no push=no
annotated-ok WIP
my-branch
"""
rewrite_branch_layout_file(body)
check_out("develop")

self.patch_symbol(mocker, 'builtins.input', mock_input_returning("n", "q"))
assert_success(
["traverse", "--sync-gitlab-mrs"],
"""
Checking for open GitLab MRs... OK
Checking out annotated-ok... OK

develop
|
o-someone-elses-branch rebase=no push=no
|
o-annotated-ok * WIP
|
o-my-branch

Branch annotated-ok does not have an MR in GitLab.
Create an MR from annotated-ok to develop? (y, d[raft], N, q, yq)

Checking out my-branch... OK

develop
|
o-someone-elses-branch rebase=no push=no
|
o-annotated-ok WIP
|
o-my-branch *

Branch my-branch does not have an MR in GitLab.
Create an MR from my-branch to develop? (y, d[raft], N, q, yq)
"""
)