Skip to content

Commit 2b5d4ee

Browse files
committed
In --related mode, always update both down- and upstream PR descriptions, even in up-only mode
1 parent 95e7ab9 commit 2b5d4ee

File tree

8 files changed

+155
-24
lines changed

8 files changed

+155
-24
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## New in git-machete 3.38.2
44

5+
- changed: `github update-pr-descriptions --related`, `gitlab update-mr-descriptions --related`, and all subcommands with `-U/--update-related-descriptions` flag now always update the entire stack (both upstream and downstream PRs/MRs); the description style still respects the `machete.github.prDescriptionIntroStyle` or `machete.gitlab.mrDescriptionIntroStyle` config setting
56
- improved: `advance` now only suggests push when the branch is ahead of remote; for other sync-to-remote statuses (behind, diverged, in sync, untracked), a warning is displayed instead
67
- improved: every time a branch is checked out, a `Checking out <branch>... OK` message is printed out for consistency
78

docs/man/git-machete.1

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
2828
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
2929
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
3030
..
31-
.TH "GIT-MACHETE" "1" "Jan 12, 2026" "" "git-machete"
31+
.TH "GIT-MACHETE" "1" "Jan 19, 2026" "" "git-machete"
3232
.SH NAME
3333
git-machete \- git-machete 3.38.2
3434
.sp
@@ -1111,9 +1111,7 @@ Update PR descriptions for all PRs authored by the given GitHub user, where \fB<
11111111
Update PR descriptions for all PRs opened by the current user associated with the GitHub token.
11121112
.TP
11131113
.B \-\-related
1114-
Update PR descriptions for all PRs that are upstream and/or downstream of the PR for the current branch.
1115-
If \fBmachete.github.prDescriptionIntroStyle\fP is \fBup\-only\fP (default) or \fBup\-only\-no\-branches\fP, then only downstream PR descriptions are updated.
1116-
If \fBmachete.github.prDescriptionIntroStyle\fP is \fBfull\fP or \fBfull\-no\-branches\fP, then both downstream and upstream PR descriptions are updated.
1114+
Update PR descriptions for all PRs both upstream and downstream of the PR for the current branch (the entire stack).
11171115
.UNINDENT
11181116
.UNINDENT
11191117
.sp
@@ -1379,9 +1377,7 @@ Update MR descriptions for all MRs authored by the given GitLab user, where \fB<
13791377
Update MR descriptions for all MRs opened by the current user associated with the GitLab token.
13801378
.TP
13811379
.B \-\-related
1382-
Update MR descriptions for all MRs that are upstream and/or downstream of the MR for the current branch.
1383-
If \fBmachete.gitlab.mrDescriptionIntroStyle\fP is \fBup\-only\fP (default) or \fBup\-only\-no\-branches\fP, then only downstream MR descriptions are updated.
1384-
If \fBmachete.gitlab.mrDescriptionIntroStyle\fP is \fBfull\fP or \fBfull\-no\-branches\fP, then both downstream and upstream MR descriptions are updated.
1380+
Update MR descriptions for all MRs both upstream and downstream of the MR for the current branch (the entire stack).
13851381
.UNINDENT
13861382
.UNINDENT
13871383
.sp

docs/source/cli/github.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ Create, check out and manage GitHub PRs while keeping them reflected in branch l
159159

160160
--mine Update PR descriptions for all PRs opened by the current user associated with the GitHub token.
161161

162-
--related Update PR descriptions for all PRs that are upstream and/or downstream of the PR for the current branch.
163-
If ``machete.github.prDescriptionIntroStyle`` is ``up-only`` (default) or ``up-only-no-branches``, then only downstream PR descriptions are updated.
164-
If ``machete.github.prDescriptionIntroStyle`` is ``full`` or ``full-no-branches``, then both downstream and upstream PR descriptions are updated.
162+
--related Update PR descriptions for all PRs both upstream and downstream of the PR for the current branch (the entire stack).
165163

166164
**Git config keys:**
167165

docs/source/cli/gitlab.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ Create, check out and manage GitLab MRs while keeping them reflected in branch l
150150

151151
--mine Update MR descriptions for all MRs opened by the current user associated with the GitLab token.
152152

153-
--related Update MR descriptions for all MRs that are upstream and/or downstream of the MR for the current branch.
154-
If ``machete.gitlab.mrDescriptionIntroStyle`` is ``up-only`` (default) or ``up-only-no-branches``, then only downstream MR descriptions are updated.
155-
If ``machete.gitlab.mrDescriptionIntroStyle`` is ``full`` or ``full-no-branches``, then both downstream and upstream MR descriptions are updated.
153+
--related Update MR descriptions for all MRs both upstream and downstream of the MR for the current branch (the entire stack).
156154

157155
**Git config keys:**
158156

git_machete/client/with_code_hosting.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -979,11 +979,9 @@ def _get_applicable_pull_requests(
979979
return []
980980
return result
981981
elif related_to:
982-
style = self.__get_pr_description_into_style_from_config()
983-
if style in (PRDescriptionIntroStyle.FULL, PRDescriptionIntroStyle.FULL_NO_BRANCHES):
984-
result = list(reversed(self.__get_upwards_path_including_pr(related_to)))
985-
else:
986-
result = [related_to]
982+
# Always update the entire stack (both upstream and downstream) when --related is used,
983+
# regardless of prDescriptionIntroStyle setting.
984+
result = list(reversed(self.__get_upwards_path_including_pr(related_to)))
987985
result += [pr_ for pr_, _ in self.__get_downwards_tree_excluding_pr(related_to)]
988986
return result
989987

git_machete/generated_docs.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,7 @@
739739
740740
--mine Update PR descriptions for all PRs opened by the current user associated with the GitHub token.
741741
742-
--related Update PR descriptions for all PRs that are upstream and/or downstream of the PR for the current branch.
743-
If `machete.github.prDescriptionIntroStyle` is `up-only` (default) or `up-only-no-branches`, then only downstream PR descriptions are updated.
744-
If `machete.github.prDescriptionIntroStyle` is `full` or `full-no-branches`, then both downstream and upstream PR descriptions are updated.
742+
--related Update PR descriptions for all PRs both upstream and downstream of the PR for the current branch (the entire stack).
745743
746744
<b>Git config keys:</b>
747745
@@ -929,9 +927,7 @@
929927
930928
--mine Update MR descriptions for all MRs opened by the current user associated with the GitLab token.
931929
932-
--related Update MR descriptions for all MRs that are upstream and/or downstream of the MR for the current branch.
933-
If `machete.gitlab.mrDescriptionIntroStyle` is `up-only` (default) or `up-only-no-branches`, then only downstream MR descriptions are updated.
934-
If `machete.gitlab.mrDescriptionIntroStyle` is `full` or `full-no-branches`, then both downstream and upstream MR descriptions are updated.
930+
--related Update MR descriptions for all MRs both upstream and downstream of the MR for the current branch (the entire stack).
935931
936932
<b>Git config keys:</b>
937933

tests/test_github_update_pr_descriptions.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,78 @@
1818

1919

2020
class TestGitHubUpdatePRDescriptions(BaseTest):
21+
def test_github_update_pr_descriptions_related_updates_entire_stack(self, mocker: MockerFixture) -> None:
22+
"""
23+
Test that --related flag updates the entire stack (both upstream and downstream PRs),
24+
even with the default up-only prDescriptionIntroStyle.
25+
26+
With the OLD logic (before PR #1574), when running `--related` from branch2 with the default
27+
up-only style, only PR #2 and PR #3 (current and downstream) would be checked/updated.
28+
PR #1 (upstream) would be skipped entirely.
29+
30+
With the NEW logic, all PRs in the stack (PR #1, PR #2, PR #3) are checked and updated,
31+
regardless of the prDescriptionIntroStyle setting.
32+
Still, the generated intro will follow the prDescriptionIntroStyle setting.
33+
"""
34+
self.patch_symbol(mocker, 'git_machete.code_hosting.OrganizationAndRepository.from_url', mock_from_url)
35+
self.patch_symbol(mocker, 'git_machete.github.GitHubToken.for_domain', mock_github_token_for_domain_fake)
36+
37+
# Create a simple 3-PR chain: PR1 -> PR2 -> PR3
38+
# Give them bodies that will need updating:
39+
# - PR #1 has an old git-machete generated section with outdated date
40+
# - PR #2 and #3 have minimal bodies that will be updated with the PR chain info
41+
prs = [
42+
mock_pr_json(head='branch1', base='root', number=1,
43+
body='<!-- start git-machete generated -->\n\n'
44+
'**Last updated: 2020-01-01**\n\n'
45+
'<!-- end git-machete generated -->\n\n'
46+
'# Summary\n\nOld content'),
47+
mock_pr_json(head='branch2', base='branch1', number=2, body='# Summary\n'),
48+
mock_pr_json(head='branch3', base='branch2', number=3, body='# Summary\n')
49+
]
50+
github_api_state = MockGitHubAPIState.with_prs(*prs)
51+
self.patch_symbol(mocker, 'urllib.request.urlopen', mock_urlopen(github_api_state))
52+
self.patch_symbol(mocker, 'git_machete.utils.get_current_date', lambda: '2023-12-31')
53+
54+
create_repo_with_remote()
55+
new_branch("root")
56+
commit("initial commit")
57+
push()
58+
new_branch("branch1")
59+
commit("branch1 commit")
60+
push()
61+
new_branch("branch2")
62+
commit("branch2 commit")
63+
push()
64+
new_branch("branch3")
65+
commit("branch3 commit")
66+
push()
67+
68+
body = """
69+
root
70+
branch1
71+
branch2
72+
branch3
73+
"""
74+
rewrite_branch_layout_file(body)
75+
76+
# Check out the middle branch (branch2)
77+
check_out('branch2')
78+
79+
# Run with `--related` from the middle branch
80+
# With the NEW logic, ALL PRs in the stack (PR1, PR2, PR3) are checked and updated
81+
# With the OLD logic (before PR #1574), only PR2 and PR3 (current and downstream) would be updated,
82+
# but NOT PR1 (upstream), because the default up-only style would exclude upstream PRs
83+
assert_success(
84+
['github', 'update-pr-descriptions', '--related'],
85+
"""
86+
Checking for open GitHub PRs... OK
87+
Description of PR #1 (branch1 -> root) has been updated
88+
Description of PR #2 (branch2 -> branch1) has been updated
89+
Description of PR #3 (branch3 -> branch2) has been updated
90+
"""
91+
)
92+
2193
@staticmethod
2294
def prs_for_test_update_pr_descriptions() -> List[Dict[str, Any]]:
2395
return [

tests/test_gitlab_update_mr_descriptions.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,78 @@
1818

1919

2020
class TestGitLabUpdateMRDescriptions(BaseTest):
21+
def test_gitlab_update_mr_descriptions_related_updates_entire_stack(self, mocker: MockerFixture) -> None:
22+
"""
23+
Test that --related flag updates the entire stack (both upstream and downstream MRs),
24+
even with the default up-only prDescriptionIntroStyle.
25+
26+
With the OLD logic (before #1574), when running `--related` from branch2 with the default
27+
up-only style, only MR #2 and MR #3 (current and downstream) would be checked/updated.
28+
MR #1 (upstream) would be skipped entirely.
29+
30+
With the NEW logic, all MRs in the stack (MR #1, MR #2, MR #3) are checked and updated,
31+
regardless of the prDescriptionIntroStyle setting.
32+
Still, the generated intro will follow the prDescriptionIntroStyle setting.
33+
"""
34+
self.patch_symbol(mocker, 'git_machete.code_hosting.OrganizationAndRepository.from_url', mock_from_url)
35+
self.patch_symbol(mocker, 'git_machete.gitlab.GitLabToken.for_domain', mock_gitlab_token_for_domain_fake)
36+
37+
# Create a simple 3-MR chain: MR1 -> MR2 -> MR3
38+
# Give them bodies that will need updating:
39+
# - MR #1 has an old git-machete generated section with outdated date
40+
# - MR #2 and #3 have minimal bodies that will be updated with the MR chain info
41+
mrs = [
42+
mock_mr_json(head='branch1', base='root', number=1,
43+
body='<!-- start git-machete generated -->\n\n'
44+
'**Last updated: 2020-01-01**\n\n'
45+
'<!-- end git-machete generated -->\n\n'
46+
'# Summary\n\nOld content'),
47+
mock_mr_json(head='branch2', base='branch1', number=2, body='# Summary\n'),
48+
mock_mr_json(head='branch3', base='branch2', number=3, body='# Summary\n')
49+
]
50+
gitlab_api_state = MockGitLabAPIState.with_mrs(*mrs)
51+
self.patch_symbol(mocker, 'urllib.request.urlopen', mock_urlopen(gitlab_api_state))
52+
self.patch_symbol(mocker, 'git_machete.utils.get_current_date', lambda: '2023-12-31')
53+
54+
create_repo_with_remote()
55+
new_branch("root")
56+
commit("initial commit")
57+
push()
58+
new_branch("branch1")
59+
commit("branch1 commit")
60+
push()
61+
new_branch("branch2")
62+
commit("branch2 commit")
63+
push()
64+
new_branch("branch3")
65+
commit("branch3 commit")
66+
push()
67+
68+
body = """
69+
root
70+
branch1
71+
branch2
72+
branch3
73+
"""
74+
rewrite_branch_layout_file(body)
75+
76+
# Check out the middle branch (branch2)
77+
check_out('branch2')
78+
79+
# Run with `--related` from the middle branch
80+
# With the NEW logic, ALL MRs in the stack (MR1, MR2, MR3) are checked and updated
81+
# With the OLD logic (before #1574), only MR2 and MR3 (current and downstream) would be updated,
82+
# but NOT MR1 (upstream), because the default up-only style would exclude upstream MRs
83+
assert_success(
84+
['gitlab', 'update-mr-descriptions', '--related'],
85+
"""
86+
Checking for open GitLab MRs... OK
87+
Description of MR !1 (branch1 -> root) has been updated
88+
Description of MR !2 (branch2 -> branch1) has been updated
89+
Description of MR !3 (branch3 -> branch2) has been updated
90+
"""
91+
)
92+
2193
@staticmethod
2294
def mrs_for_test_update_mr_descriptions() -> List[Dict[str, Any]]:
2395
return [

0 commit comments

Comments
 (0)