Skip to content

Commit f7c9328

Browse files
committed
fix(git): handle single branch argument in fetch_remote_branch
accept one-argument input when fetching remote branches by using the first argument when present, instead of requiring len(args) > 1. add regression tests for 0/1/2 argument cases to verify command execution and error behavior.
1 parent b85b8b5 commit f7c9328

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

pigit/git/_cmd_func.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def add(args: Union[List, Tuple]) -> str:
3737
def fetch_remote_branch(args: Union[List, Tuple]) -> str:
3838
"Fetch a remote branch to local and with the same name."
3939

40-
branch = args[0] if len(args) > 1 else None
40+
branch = args[0] if args else None
4141

4242
if branch:
4343
Executor().exec("git fetch origin {0}:{0} ".format(branch), flags=WAITING)

tests/test_git_cmd.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,24 @@ class TestCmdFunc:
5959
def test_add(self, _):
6060
add([])
6161

62+
@pytest.mark.parametrize(
63+
"args, expected_cmd",
64+
[
65+
([], None),
66+
(["feature/test"], "git fetch origin feature/test:feature/test "),
67+
(["feature/test", "ignored"], "git fetch origin feature/test:feature/test "),
68+
],
69+
)
6270
@patch(exec_patch, return_value=None)
63-
def test_fetch_remote(self, _):
64-
fetch_remote_branch([])
71+
def test_fetch_remote(self, mock_exec, args, expected_cmd):
72+
result = fetch_remote_branch(args)
73+
if expected_cmd is None:
74+
assert result == "`This option need a branch name.`<error>"
75+
mock_exec.assert_not_called()
76+
else:
77+
assert result == ""
78+
mock_exec.assert_called_once()
79+
assert mock_exec.call_args.args[0] == expected_cmd
6580

6681
@pytest.mark.parametrize(
6782
"args",

0 commit comments

Comments
 (0)