Repository: VirtusLab/git-machete
Pull request #1292 (2024-08-02 14:27:40)

Make `git{hub,lab} checkout-{prs,mrs}` only add qualifiers & annotations to affected branches


Patch:
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 3f6cab8..9446943 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -2,6 +2,8 @@
 
 ## New in git-machete 3.26.4
 
+- improved: `git machete git{hub,lab} checkout-{prs,mrs}` only adds annotations to affected branches (and not to every branch)
+
 ## New in git-machete 3.26.3
 
 - improved: performance of listing commits for red-edge branches on large repos
diff --git a/docs/man/git-machete.1 b/docs/man/git-machete.1
index d815e89..54c021c 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" "Jul 29, 2024" "" "git-machete"
+.TH "GIT-MACHETE" "1" "Aug 02, 2024" "" "git-machete"
 .SH NAME
 git-machete \- git-machete 3.26.4
 .sp
diff --git a/git_machete/client.py b/git_machete/client.py
index dc7dead..f70080c 100644
--- a/git_machete/client.py
+++ b/git_machete/client.py
@@ -2132,7 +2132,7 @@ class MacheteClient:
         debug(f'organization is {org_repo_remote.organization}, repository is {org_repo_remote.repository}')
         self.__git.fetch_remote(org_repo_remote.remote)
 
-        pr: Optional[PullRequest] = None
+        prs_to_annotate = set(applicable_prs)
         for pr in sorted(applicable_prs, key=lambda x: x.number):
             head_org_repo_and_git_url = code_hosting_client.get_org_repo_and_git_url_by_repo_id_or_none(pr.head_repo_id)
             if head_org_repo_and_git_url:
@@ -2164,18 +2164,19 @@ class MacheteClient:
                 warn(f'{pr.display_text()} is already closed.')
             debug(f'found {pr}')
 
-            path: List[PullRequest] = self.__get_path_from_pr_chain(spec, pr, all_open_prs)
-            reversed_path: List[PullRequest] = path[::-1]  # need to add from root downwards
-            if reversed_path[0].base not in self.managed_branches:
+            pr_path: List[PullRequest] = self.__get_path_from_pr_chain(spec, pr, all_open_prs)
+            prs_to_annotate.update(pr_path)
+            reversed_pr_path: List[PullRequest] = pr_path[::-1]  # need to add from root downwards
+            if reversed_pr_path[0].base not in self.managed_branches:
                 self.add(
-                    branch=LocalBranchShortName.of(reversed_path[0].base),
+                    branch=LocalBranchShortName.of(reversed_pr_path[0].base),
                     opt_as_first_child=False,
                     opt_as_root=True,
                     opt_onto=None,
                     opt_yes=True,
                     verbose=False,
                     switch_head_if_new_branch=False)
-            for pr_on_path in reversed_path:
+            for pr_on_path in reversed_pr_path:
                 if pr_on_path.head not in self.managed_branches:
                     self.add(
                         branch=LocalBranchShortName.of(pr_on_path.head),
@@ -2188,9 +2189,10 @@ class MacheteClient:
                     print(fmt(f"{pr_on_path.display_text()} checked out at local branch {bold(pr_on_path.head)}"))
 
         debug(f'Current {spec.display_name} user is ' + (current_user or '<none>'))
-        self.__sync_annotations_to_branch_layout_file(spec, all_open_prs, current_user=current_user, include_urls=False, verbose=False)
+        self.__sync_annotations_to_branch_layout_file(spec, list(prs_to_annotate),
+                                                      current_user=current_user, include_urls=False, verbose=False)
         if len(applicable_prs) == 1:
-            self.__git.checkout(LocalBranchShortName.of(pr.head))
+            self.__git.checkout(LocalBranchShortName.of(applicable_prs[0].head))
 
     @staticmethod
     def __get_path_from_pr_chain(spec: CodeHostingSpec, original_pr: PullRequest, all_open_prs: List[PullRequest]) -> List[PullRequest]:


Test patch:
diff --git a/tests/test_github_checkout_prs.py b/tests/test_github_checkout_prs.py
index 868c8ff..abb82e0 100644
--- a/tests/test_github_checkout_prs.py
+++ b/tests/test_github_checkout_prs.py
@@ -119,7 +119,7 @@ class TestGitHubCheckoutPRs(BaseTest):
             |
             o-hotfix/add-trigger
               |
-              o-ignore-trailing  PR #3 (some_other_user) rebase=no push=no
+              o-ignore-trailing
                 |
                 o-chore/fields
 
@@ -145,7 +145,7 @@ class TestGitHubCheckoutPRs(BaseTest):
             |
             o-hotfix/add-trigger
               |
-              o-ignore-trailing  PR #3 (some_other_user) rebase=no push=no
+              o-ignore-trailing
                 |
                 o-chore/fields
 
@@ -178,7 +178,7 @@ class TestGitHubCheckoutPRs(BaseTest):
             |
             o-hotfix/add-trigger
               |
-              o-ignore-trailing  PR #3 (some_other_user) rebase=no push=no
+              o-ignore-trailing
                 |
                 o-chore/fields
 
diff --git a/tests/test_gitlab_checkout_mrs.py b/tests/test_gitlab_checkout_mrs.py
index 89b296e..bb9adc9 100644
--- a/tests/test_gitlab_checkout_mrs.py
+++ b/tests/test_gitlab_checkout_mrs.py
@@ -121,7 +121,7 @@ class TestGitLabCheckoutMRs(BaseTest):
             |
             o-hotfix/add-trigger
               |
-              o-ignore-trailing  MR !3 (some_other_user) rebase=no push=no
+              o-ignore-trailing
                 |
                 o-chore/fields
 
@@ -147,7 +147,7 @@ class TestGitLabCheckoutMRs(BaseTest):
             |
             o-hotfix/add-trigger
               |
-              o-ignore-trailing  MR !3 (some_other_user) rebase=no push=no
+              o-ignore-trailing
                 |
                 o-chore/fields
 
@@ -180,7 +180,7 @@ class TestGitLabCheckoutMRs(BaseTest):
             |
             o-hotfix/add-trigger
               |
-              o-ignore-trailing  MR !3 (some_other_user) rebase=no push=no
+              o-ignore-trailing
                 |
                 o-chore/fields