Repository: VirtusLab/git-machete
Pull request #1364 (2024-11-01 20:26:10)

Refrain from posting trivial PR intros with just the current PR


Patch:
diff --git a/docs/man/git-machete.1 b/docs/man/git-machete.1
index 61aa9fa..f910fd1 100644
--- a/docs/man/git-machete.1
+++ b/docs/man/git-machete.1
@@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
 ..
-.TH "GIT-MACHETE" "1" "Oct 31, 2024" "" "git-machete"
+.TH "GIT-MACHETE" "1" "Nov 01, 2024" "" "git-machete"
 .SH NAME
 git-machete \- git-machete 3.31.0
 .sp
diff --git a/git_machete/client.py b/git_machete/client.py
index ee310b2..0786bbc 100644
--- a/git_machete/client.py
+++ b/git_machete/client.py
@@ -2708,19 +2708,23 @@ class MacheteClient:
             all_open_prs = code_hosting_client.get_open_pull_requests()
             print(fmt('<green><b>OK</b></green>'))
 
-        pr_up_path = reversed(self.__get_upwards_path_including_pr(spec, pr, all_open_prs))
+        pr_up_path = list(reversed(self.__get_upwards_path_including_pr(spec, pr, all_open_prs)))
         if style == PRDescriptionIntroStyle.FULL:
             pr_down_tree = self.__get_downwards_tree_excluding_pr(pr, all_open_prs)
         else:
             pr_down_tree = []
+        if len(pr_up_path) == 1 and pr_down_tree == []:
+            return ''
 
         prepend = f'{self.START_GIT_MACHETE_GENERATED_COMMENT}\n\n'
         # In FULL mode, we're likely to generate a non-empty intro even when there are NO upstream PRs above
         if len(prs_for_base_branch) >= 1:
             prepend += f'# Based on {prs_for_base_branch[0].display_text(fmt=False)}\n\n'
 
-        if pr_down_tree:
+        if pr_down_tree and len(pr_up_path) > 1:
             prepend += f'## Chain of upstream {pr_short_name}s & tree of downstream {pr_short_name}s'
+        elif pr_down_tree:
+            prepend += f'## Tree of downstream {pr_short_name}s'
         else:
             prepend += f'## Chain of upstream {pr_short_name}s'
         current_date = utils.get_current_date()


Test patch:
diff --git a/tests/test_github_retarget_pr.py b/tests/test_github_retarget_pr.py
index ea7e18d..169169f 100644
--- a/tests/test_github_retarget_pr.py
+++ b/tests/test_github_retarget_pr.py
@@ -435,7 +435,7 @@ class TestGitHubRetargetPR(BaseTest):
         assert pr15['body'] == textwrap.dedent('''
             <!-- start git-machete generated -->
 
-            ## Chain of upstream PRs & tree of downstream PRs as of 2023-12-31
+            ## Tree of downstream PRs as of 2023-12-31
 
             * **PR #15 (THIS ONE)**:
               `branch-1` ← `feature`
diff --git a/tests/test_github_update_pr_descriptions.py b/tests/test_github_update_pr_descriptions.py
index 32392aa..1ef959a 100644
--- a/tests/test_github_update_pr_descriptions.py
+++ b/tests/test_github_update_pr_descriptions.py
@@ -130,13 +130,34 @@ class TestGitHubUpdatePRDescriptions(BaseTest):
             ['github', 'update-pr-descriptions', '--all'],
             """
             Checking for open GitHub PRs... OK
-            Description of PR #19 (enhance/add_user -> develop) has been updated
             Description of PR #22 (testing/add_user -> bugfix/add_user) has been updated
             Description of PR #24 (chore/comments -> testing/add_user) has been updated
-            Description of PR #3 (ignore-trailing -> hotfix/add-trigger) has been updated
             """
         )
 
+        pr = github_api_state.get_pull_by_number(6)
+        assert pr is not None
+        assert pr['body'] == textwrap.dedent("""
+            <!-- start git-machete generated -->
+
+            ## Tree of downstream PRs as of 2023-12-31
+
+            * **PR #6 (THIS ONE)**:
+              `enhance/feature` ← `bugfix/feature`
+
+                * PR #12:
+                  `bugfix/feature` ← `allow-ownership-link`
+
+                  * PR #17:
+                    `allow-ownership-link` ← `restrict_access`
+
+                    * PR #18:
+                      `restrict_access` ← `chore/redundant_checks`
+
+            <!-- end git-machete generated -->
+
+            # Summary""")[1:]
+
         pr = github_api_state.get_pull_by_number(12)
         assert pr is not None
         assert pr['body'] == textwrap.dedent("""
@@ -162,6 +183,10 @@ class TestGitHubUpdatePRDescriptions(BaseTest):
 
             # Summary""")[1:]
 
+        pr = github_api_state.get_pull_by_number(19)
+        assert pr is not None
+        assert pr['body'] == "# Summary"
+
     def test_github_update_pr_descriptions_misc_failures_and_warns(self, mocker: MockerFixture) -> None:
         self.patch_symbol(mocker, 'git_machete.code_hosting.OrganizationAndRepository.from_url', mock_from_url)
         self.patch_symbol(mocker, 'urllib.request.urlopen', mock_urlopen(MockGitHubAPIState.with_prs()))
diff --git a/tests/test_gitlab_update_mr_descriptions.py b/tests/test_gitlab_update_mr_descriptions.py
index f0b0a1b..a74cd3d 100644
--- a/tests/test_gitlab_update_mr_descriptions.py
+++ b/tests/test_gitlab_update_mr_descriptions.py
@@ -33,6 +33,7 @@ class TestGitLabUpdateMRDescriptions(BaseTest):
         self.patch_symbol(mocker, 'git_machete.gitlab.GitLabToken.for_domain', mock_gitlab_token_for_domain_fake)
         gitlab_api_state = MockGitLabAPIState.with_mrs(*self.mrs_for_test_update_mr_descriptions())
         self.patch_symbol(mocker, 'urllib.request.urlopen', mock_urlopen(gitlab_api_state))
+        self.patch_symbol(mocker, 'git_machete.utils.get_current_date', lambda: '2023-12-31')
 
         (
             self.repo_sandbox.new_branch("root")
@@ -129,13 +130,34 @@ class TestGitLabUpdateMRDescriptions(BaseTest):
             ['gitlab', 'update-mr-descriptions', '--all'],
             """
             Checking for open GitLab MRs... OK
-            Description of MR !19 (enhance/add_user -> develop) has been updated
             Description of MR !22 (testing/add_user -> bugfix/add_user) has been updated
             Description of MR !24 (chore/comments -> testing/add_user) has been updated
-            Description of MR !3 (ignore-trailing -> hotfix/add-trigger) has been updated
             """
         )
 
+        mr = gitlab_api_state.get_mr_by_number(6)
+        assert mr is not None
+        assert mr['description'] == textwrap.dedent("""
+            <!-- start git-machete generated -->
+
+            ## Tree of downstream MRs as of 2023-12-31
+
+            * **MR !6 (THIS ONE)**:
+              `enhance/feature` ← `bugfix/feature`
+
+                * MR !12:
+                  `bugfix/feature` ← `allow-ownership-link`
+
+                  * MR !17:
+                    `allow-ownership-link` ← `restrict_access`
+
+                    * MR !18:
+                      `restrict_access` ← `chore/redundant_checks`
+
+            <!-- end git-machete generated -->
+
+            # Summary""")[1:]
+
         mr = gitlab_api_state.get_mr_by_number(12)
         assert mr is not None
         assert mr['description'] == textwrap.dedent("""
@@ -143,7 +165,7 @@ class TestGitLabUpdateMRDescriptions(BaseTest):
 
             # Based on MR !6
 
-            ## Chain of upstream MRs & tree of downstream MRs as of 2024-10-31
+            ## Chain of upstream MRs & tree of downstream MRs as of 2023-12-31
 
             * MR !6:
               `enhance/feature` ← `bugfix/feature`
@@ -161,6 +183,10 @@ class TestGitLabUpdateMRDescriptions(BaseTest):
 
             # Summary""")[1:]
 
+        mr = gitlab_api_state.get_mr_by_number(19)
+        assert mr is not None
+        assert mr['description'] == "# Summary"
+
     def test_gitlab_update_mr_descriptions_misc_failures_and_warns(self, mocker: MockerFixture) -> None:
         self.patch_symbol(mocker, 'git_machete.code_hosting.OrganizationAndRepository.from_url', mock_from_url)
         self.patch_symbol(mocker, 'urllib.request.urlopen', mock_urlopen(MockGitLabAPIState.with_mrs()))