Repository: VirtusLab/git-machete
Pull request #575 (2022-07-08 16:13:31)

Issue #571: Tidy up trailing whitespaces after `|` in the output of `git machete status`


Patch:
diff --git a/git_machete/client.py b/git_machete/client.py
index 05af7e4..6f2c3f2 100644
--- a/git_machete/client.py
+++ b/git_machete/client.py
@@ -949,7 +949,7 @@ class MacheteClient:
         next_sibling_of_ancestor: List[Optional[LocalBranchShortName]]
         for branch, next_sibling_of_ancestor in next_sibling_of_ancestor_by_branch:
             if branch in self.up_branch:
-                print_line_prefix(branch, f"{utils.get_vertical_bar()} \n")
+                print_line_prefix(branch, f"{utils.get_vertical_bar()}\n")
                 if opt_list_commits:
                     if not fp_hash(branch):
                         # Rare case, but can happen e.g. due to reflog expiry.


Test patch:
diff --git a/tests/mockers.py b/tests/mockers.py
index 7a69f72..fdab93d 100644
--- a/tests/mockers.py
+++ b/tests/mockers.py
@@ -334,8 +334,8 @@ class MockContextManager:
         pass
 
 
-def adapt(s: str) -> str:
-    return textwrap.indent(textwrap.dedent(re.sub(r"\|\n", "| \n", s[1:])), "  ")
+def adapt(s: str, indent: str) -> str:
+    return textwrap.indent(textwrap.dedent(s[1:]), indent)
 
 
 def launch_command(*args: str) -> str:
@@ -347,8 +347,9 @@ def launch_command(*args: str) -> str:
         return out.getvalue()
 
 
-def assert_command(cmds: Iterable[str], expected_result: str, strip_indentation: bool = True) -> None:
-    assert launch_command(*cmds) == (adapt(expected_result) if strip_indentation else expected_result)
+def assert_command(cmds: Iterable[str], expected_result: str, strip_indentation: bool = True, indent: str = '  ') -> None:
+    expected_result = adapt(expected_result, indent) if strip_indentation else expected_result
+    assert launch_command(*cmds) == expected_result
 
 
 def rewrite_definition_file(new_body: str) -> None:
diff --git a/tests/test_github.py b/tests/test_github.py
index 0ba9de6..92eb7c7 100644
--- a/tests/test_github.py
+++ b/tests/test_github.py
@@ -648,25 +648,26 @@ class TestGithub:
         )
 
         launch_command("discover", "-y")
-        expected_result = """Branch `feature` is untracked and there's no `origin` repository.
-[1] origin_1
-[2] origin_2
-Select number 1..2 to specify the destination remote repository, or 'q' to quit creating pull request: 
-Branch feature is untracked, but its remote counterpart candidate origin_1/feature already exists and both branches point to the same commit.
-
-  root
-  | 
-  o-branch-1
-    | 
-    o-feature *
-
-Fetching origin_1...
-Creating a PR from `feature` to `branch-1`... -> OK, see www.github.com
-"""  # noqa: W291
+        expected_result = """
+        Branch `feature` is untracked and there's no `origin` repository.
+        [1] origin_1
+        [2] origin_2
+        Select number 1..2 to specify the destination remote repository, or 'q' to quit creating pull request: 
+        Branch feature is untracked, but its remote counterpart candidate origin_1/feature already exists and both branches point to the same commit.
+
+          root
+          |
+          o-branch-1
+            |
+            o-feature *
+
+        Fetching origin_1...
+        Creating a PR from `feature` to `branch-1`... -> OK, see www.github.com
+        """  # noqa: W291
         assert_command(
             ['github', 'create-pr'],
             expected_result,
-            strip_indentation=False
+            indent=''
         )
         # branch feature_1 present in each of the remotes, tracking data present
         (
@@ -677,14 +678,15 @@ Creating a PR from `feature` to `branch-1`... -> OK, see www.github.com
                 .push(remote='origin_2')
         )
 
-        expected_result = """Added branch `feature_1` onto `feature`
-Fetching origin_2...
-Creating a PR from `feature_1` to `feature`... -> OK, see www.github.com
-"""
+        expected_result = """
+        Added branch `feature_1` onto `feature`
+        Fetching origin_2...
+        Creating a PR from `feature_1` to `feature`... -> OK, see www.github.com
+        """
         assert_command(
             ['github', 'create-pr'],
             expected_result,
-            strip_indentation=False
+            indent=''
         )
 
         # branch feature_2 not present in any of the remotes, remote origin_1 picked manually via mock_input()
@@ -694,29 +696,30 @@ Creating a PR from `feature_1` to `feature`... -> OK, see www.github.com
                 .commit('introduce feature 2')
         )
 
-        expected_result = """Added branch `feature_2` onto `feature`
-Branch `feature_2` is untracked and there's no `origin` repository.
-[1] origin_1
-[2] origin_2
-Select number 1..2 to specify the destination remote repository, or 'q' to quit creating pull request: 
-
-  root
-  | 
-  o-branch-1
-    | 
-    o-feature  PR #16
-      | 
-      o-feature_1  PR #17
-      | 
-      o-feature_2 *
-
-Fetching origin_1...
-Creating a PR from `feature_2` to `feature`... -> OK, see www.github.com
-"""  # noqa: W291
+        expected_result = """
+        Added branch `feature_2` onto `feature`
+        Branch `feature_2` is untracked and there's no `origin` repository.
+        [1] origin_1
+        [2] origin_2
+        Select number 1..2 to specify the destination remote repository, or 'q' to quit creating pull request: 
+
+          root
+          |
+          o-branch-1
+            |
+            o-feature  PR #16
+              |
+              o-feature_1  PR #17
+              |
+              o-feature_2 *
+
+        Fetching origin_1...
+        Creating a PR from `feature_2` to `feature`... -> OK, see www.github.com
+        """  # noqa: W291
         assert_command(
             ['github', 'create-pr'],
             expected_result,
-            strip_indentation=False
+            indent=''
         )
 
         # branch feature_2 present in only one remote: origin_1, no tracking data
@@ -727,28 +730,29 @@ Creating a PR from `feature_2` to `feature`... -> OK, see www.github.com
                 .push(remote='origin_1', set_upstream=False)
         )
 
-        expected_result = """Added branch `feature_3` onto `feature_2`
-Branch feature_3 is untracked, but its remote counterpart candidate origin_1/feature_3 already exists and both branches point to the same commit.
-
-  root
-  | 
-  o-branch-1
-    | 
-    o-feature  PR #16
-      | 
-      o-feature_1  PR #17
-      | 
-      o-feature_2  PR #18
-        | 
-        o-feature_3 *
-
-Fetching origin_1...
-Creating a PR from `feature_3` to `feature_2`... -> OK, see www.github.com
-"""  # noqa: W291
+        expected_result = """
+        Added branch `feature_3` onto `feature_2`
+        Branch feature_3 is untracked, but its remote counterpart candidate origin_1/feature_3 already exists and both branches point to the same commit.
+
+          root
+          |
+          o-branch-1
+            |
+            o-feature  PR #16
+              |
+              o-feature_1  PR #17
+              |
+              o-feature_2  PR #18
+                |
+                o-feature_3 *
+
+        Fetching origin_1...
+        Creating a PR from `feature_3` to `feature_2`... -> OK, see www.github.com
+        """
         assert_command(
             ['github', 'create-pr'],
             expected_result,
-            strip_indentation=False
+            indent=''
         )
 
         # branch feature_3 present in only one remote: origin_2, tracking data present
diff --git a/tests/test_status.py b/tests/test_status.py
index ce6ef45..5041710 100644
--- a/tests/test_status.py
+++ b/tests/test_status.py
@@ -69,24 +69,26 @@ class TestStatus:
         launch_command('discover', '-y')
 
         expected_status_output = (
-"""   master
-   | 
-   o- bar
-      | 
-      o- foo *
-"""  # noqa: E122, W291
+            """
+            master
+            |
+            o- bar
+               |
+               o- foo *
+            """
         )
-        assert_command(['status'], expected_status_output, strip_indentation=False)
+        assert_command(['status'], expected_status_output, indent='   ')
 
         self.repo_sandbox.add_git_config_key('machete.status.extraSpaceBeforeBranchName', 'false')
 
         expected_status_output = (
-"""  master
- |
- o-bar
-   |
-   o-foo *
-"""  # noqa: E122
+            """
+            master
+            |
+            o-bar
+              |
+              o-foo *
+            """
         )
         assert_command(['status'], expected_status_output)
 
@@ -268,14 +270,14 @@ class TestStatus:
         launch_command('discover', '-y')
         expected_status_output = (
 """  master
-  | 
+  |
   o-bar
-    | 
+    |
     o-foo (untracked)
-      | 
+      |
       o-snickers
-        | 
+        |
         o-mars *
-"""  # noqa: E122, W291
+"""  # noqa: E122
         )
         assert_command(['status'], expected_status_output, strip_indentation=False)