Repository: VirtusLab/git-machete
Pull request #546 (2022-06-10 13:03:41)

Issue #541: Change branch switch logic in `git machete checkout-prs`

codecov-commenter: # [Codecov](https://codecov.io/gh/VirtusLab/git-machete/pull/546?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab) Report
> Merging [#546](https://codecov.io/gh/VirtusLab/git-machete/pull/546?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab) (25b23d5) into [develop](https://codecov.io/gh/VirtusLab/git-machete/commit/d4e4ccef5452193d55467561927d6d9cc49d333d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab) (d4e4cce) will **not change** coverage.
> The diff coverage is `100.00%`.

```diff
@@           Coverage Diff            @@
##           develop     #546   +/-   ##
========================================
  Coverage    66.68%   66.68%           
========================================
  Files           10       10           
  Lines         2864     2864           
  Branches       696      696           
========================================
  Hits          1910     1910           
  Misses         690      690           
  Partials       264      264           
```


| [Impacted Files](https://codecov.io/gh/VirtusLab/git-machete/pull/546?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab) | Coverage Δ | |
|---|---|---|
| [git\_machete/client.py](https://codecov.io/gh/VirtusLab/git-machete/pull/546/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab#diff-Z2l0X21hY2hldGUvY2xpZW50LnB5) | `61.97% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/VirtusLab/git-machete/pull/546?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/VirtusLab/git-machete/pull/546?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab). Last update [d4e4cce...25b23d5](https://codecov.io/gh/VirtusLab/git-machete/pull/546?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab).


Patch:
diff --git a/git_machete/client.py b/git_machete/client.py
index 19ef0c4..86dba58 100644
--- a/git_machete/client.py
+++ b/git_machete/client.py
@@ -1934,7 +1934,7 @@ class MacheteClient:
 
         debug('Current GitHub user is ' + (current_user or '<none>'))
         self.__sync_annotations_to_definition_file(all_open_prs, current_user, verbose=verbose)
-        if pr and len(checked_out_prs) == 1:
+        if len(applicable_prs) == 1:
             self.__git.checkout(LocalBranchShortName.of(pr.head))
             if verbose:
                 print(fmt(f"Switched to local branch `{pr.head}`"))


Test patch:
diff --git a/tests/test_github.py b/tests/test_github.py
index d8fce10..71d0439 100644
--- a/tests/test_github.py
+++ b/tests/test_github.py
@@ -1045,7 +1045,7 @@ class TestGithub:
 
         expected_status_output = (
             """
-            master *
+            master
             |
             o-bar (untracked)
             |
@@ -1053,7 +1053,7 @@ class TestGithub:
             |
             o-moo (untracked)
             |
-            o-snickers  PR #7
+            o-snickers *  PR #7
             """
         )
         assert_command(['status'], expected_status_output)