Skip to content

Commit cd7f132

Browse files
dtrifiropmrowla
authored andcommitted
tests: add test_iter_remote_refs
1 parent c0ead1c commit cd7f132

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

tests/test_git.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
from pytest_test_utils import TempDirFactory, TmpDir
1010
from pytest_test_utils.matchers import Matcher
1111

12-
from scmrepo.exceptions import MergeConflictError, RevError, SCMError
12+
from scmrepo.exceptions import (
13+
InvalidRemote,
14+
MergeConflictError,
15+
RevError,
16+
SCMError,
17+
)
1318
from scmrepo.git import Git
1419

1520
# pylint: disable=redefined-outer-name,unused-argument,protected-access
@@ -417,6 +422,44 @@ def test_fetch_refspecs(
417422
assert baz_rev == scm.get_ref("refs/foo/baz")
418423

419424

425+
@pytest.mark.skip_git_backend("pygit2", "gitpython")
426+
@pytest.mark.parametrize("use_url", [True, False])
427+
def test_iter_remote_refs(
428+
tmp_dir: TmpDir,
429+
scm: Git,
430+
git: Git,
431+
remote_git_dir: TmpDir,
432+
tmp_dir_factory: TempDirFactory,
433+
use_url: bool,
434+
):
435+
url = f"file://{remote_git_dir.resolve().as_posix()}"
436+
437+
scm.gitpython.repo.create_remote("origin", url)
438+
remote_scm = Git(remote_git_dir)
439+
remote_git_dir.gen("file", "0")
440+
remote_scm.add_commit("file", message="init")
441+
remote_scm.branch("new-branch")
442+
remote_scm.add_commit("file", message="bar")
443+
remote_scm.add_commit("file", message="baz")
444+
remote_scm.tag("a-tag")
445+
446+
with pytest.raises(InvalidRemote):
447+
set(git.iter_remote_refs("bad-remote"))
448+
449+
with pytest.raises(InvalidRemote):
450+
tmp_directory = tmp_dir_factory.mktemp("not_a_git_repo")
451+
remote = f"file://{tmp_directory.as_posix()}"
452+
set(git.iter_remote_refs(remote))
453+
454+
remote = url if use_url else "origin"
455+
assert {
456+
"refs/heads/master",
457+
"HEAD",
458+
"refs/heads/new-branch",
459+
"refs/tags/a-tag",
460+
} == set(git.iter_remote_refs(remote))
461+
462+
420463
@pytest.mark.skip_git_backend("dulwich", "pygit2")
421464
def test_list_all_commits(
422465
tmp_dir: TmpDir, scm: Git, git: Git, matcher: Type[Matcher]

0 commit comments

Comments
 (0)