Repository: VirtusLab/git-machete
Pull request #1452 (2025-06-27 19:42:08)

Fix `traverse` not checking out a branch that only requires creating a PR/MR


Patch:
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index edcea14..70b2945 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -2,6 +2,8 @@
 
 ## New in git-machete 3.36.1
 
+- fixed: incorrect `Could not determine base branch for PR` error messages when creating PRs from `git machete traverse -H`
+
 ## New in git-machete 3.36.0
 
 - deprecated: `git machete fork-point --override-to=...` and `--override-to-inferred` options; use `--override-to-parent`, or run `git machete update [--fork-point=...]` instead
diff --git a/docs/man/git-machete.1 b/docs/man/git-machete.1
index 0c6ed34..a3b9054 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" "Jun 16, 2025" "" "git-machete"
+.TH "GIT-MACHETE" "1" "Jun 27, 2025" "" "git-machete"
 .SH NAME
 git-machete \- git-machete 3.36.1
 .sp
diff --git a/git_machete/client/traverse.py b/git_machete/client/traverse.py
index 1efef77..4f705c0 100644
--- a/git_machete/client/traverse.py
+++ b/git_machete/client/traverse.py
@@ -137,7 +137,8 @@ class TraverseMacheteClient(MacheteClientWithCodeHosting):
                 if needs_parent_sync and branch in self.annotations:
                     needs_parent_sync = self.annotations[branch].qualifiers.rebase
 
-            if branch != current_branch and (needs_slide_out or needs_parent_sync or needs_remote_sync or needs_retarget_pr):
+            needs_any_action = needs_slide_out or needs_parent_sync or needs_remote_sync or needs_retarget_pr or needs_create_pr
+            if branch != current_branch and needs_any_action:
                 self._print_new_line(False)
                 print(f"Checking out {bold(branch)}")
                 self._git.checkout(branch)
diff --git a/git_machete/utils.py b/git_machete/utils.py
index 5eb65cf..f73a3e2 100644
--- a/git_machete/utils.py
+++ b/git_machete/utils.py
@@ -285,7 +285,9 @@ def slurp_file(path: str) -> str:
 def is_terminal_fully_fledged() -> bool:
     try:
         stdout = popen_cmd('tput', 'colors')[1]
-        number_of_supported_colors = int(stdout)  # in CI, this line is only covered by tests on macOS
+        # In CI, this line is only covered by tests on macOS, which don't run on PRs by default.
+        # Let's skip to keep coverage results consistent between develop/master and PRs.
+        number_of_supported_colors = int(stdout)  # pragma: no cover
     except Exception:
         # If we cannot retrieve the number of supported colors, let's defensively assume it's low.
         number_of_supported_colors = 8


Test patch:
diff --git a/tests/test_traverse_github.py b/tests/test_traverse_github.py
index c73f2e4..2471ebd 100644
--- a/tests/test_traverse_github.py
+++ b/tests/test_traverse_github.py
@@ -285,11 +285,24 @@ class TestTraverseGitHub(BaseTest):
             """
         )
 
+        check_out("develop")
         self.patch_symbol(mocker, 'builtins.input', mock_input_returning("yq"))
         assert_success(
             ["traverse", "--sync-github-prs"],
             """
             Checking for open GitHub PRs... OK
+            Checking out allow-ownership-link
+
+              develop
+              |
+              o-allow-ownership-link *
+                |
+                o-build-chain (untracked)
+                  |
+                  o-call-ws  PR #1
+                    |
+                    o-drop-constraint (untracked)
+
             Branch allow-ownership-link does not have a PR in GitHub.
             Create a PR from allow-ownership-link to develop? (y, d[raft], N, q, yq)
             Checking if base branch develop exists in origin remote... YES