Skip to content

Commit 6c19600

Browse files
committed
git_utils: Fix '--force' option
1 parent 62f5aa4 commit 6c19600

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/mbed_tools/project/_internal/git_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def checkout(repo: git.Repo, ref: str, force: bool = False) -> None:
5555
VersionControlError: Check out failed.
5656
"""
5757
try:
58-
repo.git.checkout(f"--force {ref}" if force else str(ref))
58+
git_args = [ref] + ["--force"] if force else []
59+
repo.git.checkout(*git_args)
5960
except git.exc.GitCommandError as err:
6061
raise VersionControlError(f"Failed to check out revision '{ref}'. Error from VCS: {err}")
6162

tests/project/_internal/test_git_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class TestCheckout:
8686
def test_git_lib_called_with_correct_command(self, mock_repo):
8787
git_utils.checkout(mock_repo, "master", force=True)
8888

89-
mock_repo.git.checkout.assert_called_once_with("--force master")
89+
mock_repo.git.checkout.assert_called_once_with("master", "--force")
9090

9191
def test_raises_version_control_error_when_git_checkout_fails(self, mock_repo):
9292
mock_repo.git.checkout.side_effect = git_utils.git.exc.GitCommandError("git checkout", 255)

0 commit comments

Comments
 (0)