|
9 | 9 | from pytest_test_utils import TempDirFactory, TmpDir
|
10 | 10 | from pytest_test_utils.matchers import Matcher
|
11 | 11 |
|
12 |
| -from scmrepo.exceptions import MergeConflictError, RevError, SCMError |
| 12 | +from scmrepo.exceptions import ( |
| 13 | + InvalidRemote, |
| 14 | + MergeConflictError, |
| 15 | + RevError, |
| 16 | + SCMError, |
| 17 | +) |
13 | 18 | from scmrepo.git import Git
|
14 | 19 |
|
15 | 20 | # pylint: disable=redefined-outer-name,unused-argument,protected-access
|
@@ -417,6 +422,44 @@ def test_fetch_refspecs(
|
417 | 422 | assert baz_rev == scm.get_ref("refs/foo/baz")
|
418 | 423 |
|
419 | 424 |
|
| 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 | + |
420 | 463 | @pytest.mark.skip_git_backend("dulwich", "pygit2")
|
421 | 464 | def test_list_all_commits(
|
422 | 465 | tmp_dir: TmpDir, scm: Git, git: Git, matcher: Type[Matcher]
|
|
0 commit comments