Repository: VirtusLab/git-machete
Pull request #256 (2021-09-28 07:16:58)

fix for `u` alias in `go` command
 - fixed `u` alias
 - added tests for short commands and parameters 


Patch:
diff --git a/git_machete/client.py b/git_machete/client.py
index 9439501..79c9ebf 100644
--- a/git_machete/client.py
+++ b/git_machete/client.py
@@ -1329,7 +1329,7 @@ class MacheteClient:
             return self.prev_branch(branch)
         elif param in ("r", "root"):
             return self.root_branch(branch, if_unmanaged=PICK_FIRST_ROOT)
-        elif param in ("upstream", "up"):
+        elif param in ("u", "up"):
             return self.up(branch, prompt_if_inferred_msg=None, prompt_if_inferred_yes_opt_msg=None)
         else:
             raise MacheteException(f"Invalid direction: `{param}` expected: {allowed_directions(allow_current)}")


Test patch:
diff --git a/git_machete/tests/functional/test_machete.py b/git_machete/tests/functional/test_machete.py
index dd0d6e8..eaf251e 100644
--- a/git_machete/tests/functional/test_machete.py
+++ b/git_machete/tests/functional/test_machete.py
@@ -931,6 +931,15 @@ class MacheteTester(unittest.TestCase):
             msg="Verify that 'git machete go up' performs 'git checkout' to "
                 "the parent/upstream branch of the current branch."
         )
+        # check short command behaviour
+        self.repo_sandbox.check_out("level-1-branch")
+        self.launch_command("g", "u")
+        self.assertEqual(
+            'level-0-branch',
+            self.launch_command("show", "current").strip(),
+            msg="Verify that 'git machete g u' performs 'git checkout' to "
+                "the parent/upstream branch of the current branch."
+        )
 
     def test_go_down(self) -> None:
         """Verify behaviour of a 'git machete go down' command.
@@ -956,6 +965,15 @@ class MacheteTester(unittest.TestCase):
             msg="Verify that 'git machete go down' performs 'git checkout' to "
                 "the child/downstream branch of the current branch."
         )
+        # check short command behaviour
+        self.repo_sandbox.check_out("level-0-branch")
+        self.launch_command("g", "d")
+
+        self.assertEqual(
+            'level-1-branch',
+            self.launch_command("show", "current").strip(),
+            msg="Verify that 'git machete g d' performs 'git checkout' to "
+                "the child/downstream branch of the current branch.")
 
     def test_go_first_root_with_downstream(self) -> None:
         """Verify behaviour of a 'git machete go first' command.
@@ -998,6 +1016,16 @@ class MacheteTester(unittest.TestCase):
                 "has any downstream branches."
         )
 
+        # check short command behaviour
+        self.repo_sandbox.check_out("level-3b-branch")
+        self.launch_command("g", "f")
+
+        self.assertEqual(
+            'level-1a-branch',
+            self.launch_command("show", "current").strip(),
+            msg="Verify that 'git machete g d' performs 'git checkout' to "
+                "the child/downstream branch of the current branch.")
+
     def test_go_first_root_without_downstream(self) -> None:
         """Verify behaviour of a 'git machete go first' command.
 
@@ -1020,6 +1048,16 @@ class MacheteTester(unittest.TestCase):
                 "if root branch has no downstream."
         )
 
+        # check short command behaviour
+        self.launch_command("g", "f")
+
+        self.assertEqual(
+            'level-0-branch',
+            self.launch_command("show", "current").strip(),
+            msg="Verify that 'git machete g f' set current branch to root"
+                "if root branch has no downstream."
+        )
+
     def test_go_last(self) -> None:
         """Verify behaviour of a 'git machete go last' command.
 
@@ -1057,6 +1095,18 @@ class MacheteTester(unittest.TestCase):
                 "has any downstream branches."
         )
 
+        # check short command behaviour
+        self.repo_sandbox.check_out("level-1a-branch")
+        self.launch_command("g", "l")
+
+        self.assertEqual(
+            'level-1b-branch',
+            self.launch_command("show", "current").strip(),
+            msg="Verify that 'git machete g l' performs 'git checkout' to"
+                "the last downstream branch of a root branch if root branch "
+                "has any downstream branches."
+        )
+
     def test_go_next_successor_exists(self) -> None:
         """Verify behaviour of a 'git machete go next' command.
 
@@ -1088,6 +1138,17 @@ class MacheteTester(unittest.TestCase):
                 "the next downstream branch right after the current one in the"
                 "config file if successor branch exists."
         )
+        # check short command behaviour
+        self.repo_sandbox.check_out("level-2a-branch")
+        self.launch_command("g", "n")
+
+        self.assertEqual(
+            'level-1b-branch',
+            self.launch_command("show", "current").strip(),
+            msg="Verify that 'git machete g n' performs 'git checkout' to"
+                "the next downstream branch right after the current one in the"
+                "config file if successor branch exists."
+        )
 
     def test_go_next_successor_on_another_root_tree(self) -> None:
         """Verify behaviour of a 'git machete go next' command.
@@ -1115,6 +1176,15 @@ class MacheteTester(unittest.TestCase):
             msg="Verify that 'git machete go next' can checkout to branch that doesn't"
                 "share root with the current branch.")
 
+        # check short command behaviour
+        self.repo_sandbox.check_out("level-1-branch")
+        self.launch_command("g", "n")
+        self.assertEqual(
+            'x-additional-root',
+            self.launch_command("show", "current").strip(),
+            msg="Verify that 'git machete g n' can checkout to branch that doesn't"
+                "share root with the current branch.")
+
     def test_go_prev_successor_exists(self) -> None:
         """Verify behaviour of a 'git machete go prev' command.
 
@@ -1145,6 +1215,17 @@ class MacheteTester(unittest.TestCase):
                 "the branch right before the current one in the config file"
                 "when predecessor branch exists within the root tree."
         )
+        # check short command behaviour
+        self.repo_sandbox.check_out("level-1b-branch")
+        self.launch_command("g", "p")
+
+        self.assertEqual(
+            'level-2a-branch',
+            self.launch_command("show", "current").strip(),
+            msg="Verify that 'git machete g p' performs 'git checkout' to"
+                "the branch right before the current one in the config file"
+                "when predecessor branch exists within the root tree."
+        )
 
     def test_go_prev_successor_on_another_root_tree(self) -> None:
         """Verify behaviour of a 'git machete go prev' command.
@@ -1170,6 +1251,15 @@ class MacheteTester(unittest.TestCase):
             msg="Verify that 'git machete go prev' can checkout to branch that doesn't"
                 "share root with the current branch.")
 
+        # check short command behaviour
+        self.repo_sandbox.check_out("level-0-branch")
+        self.launch_command("g", "p")
+        self.assertEqual(
+            'a-additional-root',
+            self.launch_command("show", "current").strip(),
+            msg="Verify that 'git machete g p' can checkout to branch that doesn't"
+                "share root with the current branch.")
+
     def test_go_root(self) -> None:
         """Verify behaviour of a 'git machete go root' command.
 
@@ -1203,6 +1293,15 @@ class MacheteTester(unittest.TestCase):
             msg="Verify that 'git machete go root' performs 'git checkout' to"
                 "the root of the current branch."
         )
+        # check short command behaviour
+        self.repo_sandbox.check_out("level-2a-branch")
+        self.launch_command("g", "r")
+        self.assertEqual(
+            'level-0-branch',
+            self.launch_command("show", "current").strip(),
+            msg="Verify that 'git machete g r' performs 'git checkout' to"
+                "the root of the current branch."
+        )
 
     def test_show_up(self) -> None:
         """Verify behaviour of a 'git machete show up' command.
@@ -1226,6 +1325,13 @@ class MacheteTester(unittest.TestCase):
             msg="Verify that 'git machete show up' displays name of a parent/upstream"
                 "branch one above current one."
         )
+        # check short command behaviour
+        self.assertEqual(
+            'level-0-branch',
+            self.launch_command("show", "u").strip(),
+            msg="Verify that 'git machete show u' displays name of a parent/upstream"
+                "branch one above current one."
+        )
 
     def test_show_down(self) -> None:
         """Verify behaviour of a 'git machete show down' command.
@@ -1249,6 +1355,13 @@ class MacheteTester(unittest.TestCase):
             msg="Verify that 'git machete show down' displays name of "
                 "a child/downstream branch one below current one."
         )
+        # check short command behaviour
+        self.assertEqual(
+            'level-1-branch',
+            self.launch_command("show", "d").strip(),
+            msg="Verify that 'git machete show d' displays name of "
+                "a child/downstream branch one below current one."
+        )
 
     def test_show_first(self) -> None:
         """Verify behaviour of a 'git machete show first' command.
@@ -1288,6 +1401,14 @@ class MacheteTester(unittest.TestCase):
                 "branch of a root branch of the current branch in the config file if root"
                 "branch has any downstream branches."
         )
+        # check short command behaviour
+        self.assertEqual(
+            'level-1a-branch',
+            self.launch_command("show", "f").strip(),
+            msg="Verify that 'git machete show f' displays name of the first downstream"
+                "branch of a root branch of the current branch in the config file if root"
+                "branch has any downstream branches."
+        )
 
     def test_show_last(self) -> None:
         """Verify behaviour of a 'git machete show last' command.
@@ -1323,6 +1444,14 @@ class MacheteTester(unittest.TestCase):
                 "branch of a root branch of the current branch in the config file if root"
                 "branch has any downstream branches."
         )
+        # check short command behaviour
+        self.assertEqual(
+            'level-1b-branch',
+            self.launch_command("show", "l").strip(),
+            msg="Verify that 'git machete show l' displays name of the last downstream"
+                "branch of a root branch of the current branch in the config file if root"
+                "branch has any downstream branches."
+        )
 
     def test_show_next(self) -> None:
         """Verify behaviour of a 'git machete show next' command.
@@ -1353,6 +1482,14 @@ class MacheteTester(unittest.TestCase):
                 "a branch right after the current one in the config file"
                 "when successor branch exists within the root tree."
         )
+        # check short command behaviour
+        self.assertEqual(
+            'level-1b-branch',
+            self.launch_command("show", "n").strip(),
+            msg="Verify that 'git machete show n' displays name of "
+                "a branch right after the current one in the config file"
+                "when successor branch exists within the root tree."
+        )
 
     def test_show_prev(self) -> None:
         """Verify behaviour of a 'git machete show prev' command.
@@ -1382,6 +1519,14 @@ class MacheteTester(unittest.TestCase):
                 "a branch right before the current one in the config file"
                 "when predecessor branch exists within the root tree."
         )
+        # check short command behaviour
+        self.assertEqual(
+            'level-2a-branch',
+            self.launch_command("show", "p").strip(),
+            msg="Verify that 'git machete show p' displays name of"
+                "a branch right before the current one in the config file"
+                "when predecessor branch exists within the root tree."
+        )
 
     def test_show_root(self) -> None:
         """Verify behaviour of a 'git machete show root' command.
@@ -1414,6 +1559,13 @@ class MacheteTester(unittest.TestCase):
             msg="Verify that 'git machete show root' displays name of the root of"
                 "the current branch."
         )
+        # check short command behaviour
+        self.assertEqual(
+            'level-0-branch',
+            self.launch_command("show", "r").strip(),
+            msg="Verify that 'git machete show r' displays name of the root of"
+                "the current branch."
+        )
 
     def test_advance_with_no_downstream_branches(self) -> None:
         """Verify behaviour of a 'git machete advance' command.