Skip to content

Commit 52d0f84

Browse files
committed
Add test_github_update_pr_descriptions_related_updates_entire_stack
1 parent 41a0bae commit 52d0f84

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

docs/man/git-machete.1

Lines changed: 1 addition & 1 deletion
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 13, 2026" "" "git-machete"
3232
.SH NAME
3333
git-machete \- git-machete 3.38.2
3434
.sp

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 [

0 commit comments

Comments
 (0)