@@ -552,12 +552,34 @@ def hg_remote_repo_single_commit_post_init(remote_repo_path: pathlib.Path) -> No
552
552
run (["hg" , "commit" , "-m" , "test file for hg repo" ], cwd = remote_repo_path )
553
553
554
554
555
- @pytest .fixture
555
+ @pytest .fixture (scope = "session" )
556
+ def empty_hg_repo_path (libvcs_test_cache_path : pathlib .Path ) -> pathlib .Path :
557
+ """Return temporary directory to use for master-copy of a hg repo."""
558
+ return libvcs_test_cache_path / "empty_hg_repo"
559
+
560
+
561
+ @pytest .fixture (scope = "session" )
562
+ @skip_if_hg_missing
563
+ def empty_hg_repo (
564
+ empty_hg_repo_path : pathlib .Path ,
565
+ ) -> pathlib .Path :
566
+ """Return factory to create hg remote repo to for clone / push purposes."""
567
+ if empty_hg_repo_path .exists () and (empty_hg_repo_path / ".hg" ).exists ():
568
+ return empty_hg_repo_path
569
+
570
+ return _create_hg_remote_repo (
571
+ remote_repos_path = empty_hg_repo_path .parent ,
572
+ remote_repo_name = empty_hg_repo_path .stem ,
573
+ remote_repo_post_init = None ,
574
+ init_cmd_args = None ,
575
+ )
576
+
577
+
578
+ @pytest .fixture (scope = "session" )
556
579
@skip_if_hg_missing
557
580
def create_hg_remote_repo (
558
581
remote_repos_path : pathlib .Path ,
559
- hgconfig : pathlib .Path ,
560
- set_home : pathlib .Path ,
582
+ empty_hg_repo : pathlib .Path ,
561
583
) -> CreateRepoPytestFixtureFn :
562
584
"""Pre-made hg repo, bare, used as a file:// remote to checkout and commit to."""
563
585
@@ -567,30 +589,39 @@ def fn(
567
589
remote_repo_post_init : Optional [CreateRepoPostInitFn ] = None ,
568
590
init_cmd_args : InitCmdArgs = None ,
569
591
) -> pathlib .Path :
570
- return _create_hg_remote_repo (
571
- remote_repos_path = remote_repos_path ,
572
- remote_repo_name = remote_repo_name
573
- if remote_repo_name is not None
574
- else unique_repo_name (remote_repos_path = remote_repos_path ),
575
- remote_repo_post_init = remote_repo_post_init ,
576
- init_cmd_args = init_cmd_args ,
577
- )
592
+ if remote_repo_name is None :
593
+ remote_repo_name = unique_repo_name (remote_repos_path = remote_repos_path )
594
+ remote_repo_path = remote_repos_path / remote_repo_name
595
+
596
+ shutil .copytree (empty_hg_repo , remote_repo_path )
597
+
598
+ if remote_repo_post_init is not None and callable (remote_repo_post_init ):
599
+ remote_repo_post_init (remote_repo_path = remote_repo_path )
600
+
601
+ assert empty_hg_repo .exists ()
602
+
603
+ assert remote_repo_path .exists ()
604
+
605
+ return remote_repo_path
578
606
579
607
return fn
580
608
581
609
582
- @pytest .fixture
610
+ @pytest .fixture ( scope = "session" )
583
611
@skip_if_hg_missing
584
612
def hg_remote_repo (
585
613
remote_repos_path : pathlib .Path ,
586
- hgconfig : pathlib . Path ,
614
+ create_hg_remote_repo : CreateRepoPytestFixtureFn ,
587
615
) -> pathlib .Path :
588
616
"""Pre-made, file-based repo for push and pull."""
589
- return _create_hg_remote_repo (
590
- remote_repos_path = remote_repos_path ,
591
- remote_repo_name = "dummyrepo" ,
592
- remote_repo_post_init = hg_remote_repo_single_commit_post_init ,
593
- )
617
+ # return _create_hg_remote_repo(
618
+ # remote_repos_path=remote_repos_path,
619
+ # remote_repo_name="dummyrepo",
620
+ # remote_repo_post_init=hg_remote_repo_single_commit_post_init,
621
+ # )
622
+ repo_path = create_hg_remote_repo ()
623
+ hg_remote_repo_single_commit_post_init (remote_repo_path = repo_path )
624
+ return repo_path
594
625
595
626
596
627
@pytest .fixture
@@ -640,6 +671,7 @@ def add_doctest_fixtures(
640
671
tmp_path : pathlib .Path ,
641
672
set_home : pathlib .Path ,
642
673
gitconfig : pathlib .Path ,
674
+ hgconfig : pathlib .Path ,
643
675
create_git_remote_repo : CreateRepoPytestFixtureFn ,
644
676
create_svn_remote_repo : CreateRepoPytestFixtureFn ,
645
677
create_hg_remote_repo : CreateRepoPytestFixtureFn ,
@@ -667,6 +699,7 @@ def add_doctest_fixtures(
667
699
remote_repo_post_init = svn_remote_repo_single_commit_post_init ,
668
700
)
669
701
if shutil .which ("hg" ):
702
+ doctest_namespace ["hgconfig" ] = hgconfig
670
703
doctest_namespace ["create_hg_remote_repo_bare" ] = create_hg_remote_repo
671
704
doctest_namespace ["create_hg_remote_repo" ] = functools .partial (
672
705
create_hg_remote_repo ,
0 commit comments