Skip to content

Commit 9627306

Browse files
committed
test(git): add test for get_default_branch
1 parent e680ab8 commit 9627306

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/test_git.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,3 +480,22 @@ def test_create_commit_cmd_string(mocker, os_name, committer_date, expected_cmd)
480480
mocker.patch("os.name", os_name)
481481
result = git._create_commit_cmd_string("", committer_date, "temp.txt")
482482
assert result == expected_cmd
483+
484+
485+
def test_get_default_branch(mocker: MockFixture):
486+
# Test successful case
487+
mocker.patch(
488+
"commitizen.cmd.run", return_value=FakeCommand(out="refs/remotes/origin/main\n")
489+
)
490+
assert git.get_default_branch() == "refs/remotes/origin/main"
491+
492+
# Test error case
493+
mocker.patch(
494+
"commitizen.cmd.run",
495+
return_value=FakeCommand(
496+
err="fatal: ref refs/remotes/origin/HEAD is not a symbolic ref",
497+
return_code=1,
498+
),
499+
)
500+
with pytest.raises(exceptions.GitCommandError):
501+
git.get_default_branch()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy