Skip to content

Commit 7d4ce47

Browse files
sumoemilypi
andauthored
Add support for hg version control system (#7133)
* Add sync support for hg * Updated VCS tests to include hg. cabal.project requires tests enabled for cabal-install Co-authored-by: Emily Pillmore <[email protected]>
1 parent 8f5b2f0 commit 7d4ce47

File tree

2 files changed

+98
-1
lines changed
  • cabal-install
    • src/Distribution/Client
    • tests/UnitTests/Distribution/Client

2 files changed

+98
-1
lines changed

cabal-install/src/Distribution/Client/VCS.hs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,35 @@ vcsHg =
490490
-> ConfiguredProgram
491491
-> [(SourceRepositoryPackage f, FilePath)]
492492
-> IO [MonitorFilePath]
493-
vcsSyncRepos _v _p _rs = fail "sync repo not yet supported for hg"
493+
vcsSyncRepos _ _ [] = return []
494+
vcsSyncRepos verbosity hgProg
495+
((primaryRepo, primaryLocalDir) : secondaryRepos) = do
496+
vcsSyncRepo verbosity hgProg primaryRepo primaryLocalDir
497+
sequence_
498+
[ vcsSyncRepo verbosity hgProg repo localDir
499+
| (repo, localDir) <- secondaryRepos ]
500+
return [ monitorDirectoryExistence dir
501+
| dir <- (primaryLocalDir : map snd secondaryRepos) ]
502+
vcsSyncRepo verbosity hgProg repo localDir = do
503+
exists <- doesDirectoryExist localDir
504+
if exists
505+
then hg localDir ["pull"]
506+
else hg (takeDirectory localDir) cloneArgs
507+
hg localDir checkoutArgs
508+
where
509+
hg :: FilePath -> [String] -> IO ()
510+
hg cwd args = runProgramInvocation verbosity $
511+
(programInvocation hgProg args) {
512+
progInvokeCwd = Just cwd
513+
}
514+
cloneArgs = ["clone", "--noupdate", (srpLocation repo), localDir]
515+
++ verboseArg
516+
verboseArg = [ "--quiet" | verbosity < Verbosity.normal ]
517+
checkoutArgs = [ "checkout", "--clean" ]
518+
++ tagArgs
519+
tagArgs = case srpTag repo of
520+
Just t -> ["--rev", t]
521+
Nothing -> []
494522

495523
hgProgram :: Program
496524
hgProgram = (simpleProgram "hg") {

cabal-install/tests/UnitTests/Distribution/Client/VCS.hs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ tests mtimeChange =
6666
, testProperty "syncSourceRepos" prop_syncRepos_pijul
6767
]
6868

69+
, testGroup "mercurial" $ const []
70+
[ testProperty "check VCS test framework" prop_framework_hg
71+
, testProperty "cloneSourceRepo" prop_cloneRepo_hg
72+
, testProperty "syncSourceRepos" prop_syncRepos_hg
73+
]
74+
6975
]
7076

7177
prop_framework_git :: BranchingRepoRecipe -> Property
@@ -86,6 +92,12 @@ prop_framework_pijul =
8692
. prop_framework vcsPijul vcsTestDriverPijul
8793
. WithBranchingSupport
8894

95+
prop_framework_hg :: BranchingRepoRecipe -> Property
96+
prop_framework_hg =
97+
ioProperty
98+
. prop_framework vcsHg vcsTestDriverHg
99+
. WithBranchingSupport
100+
89101
prop_cloneRepo_git :: BranchingRepoRecipe -> Property
90102
prop_cloneRepo_git =
91103
ioProperty
@@ -105,6 +117,12 @@ prop_cloneRepo_pijul =
105117
. prop_cloneRepo vcsPijul vcsTestDriverPijul
106118
. WithBranchingSupport
107119

120+
prop_cloneRepo_hg :: BranchingRepoRecipe -> Property
121+
prop_cloneRepo_hg =
122+
ioProperty
123+
. prop_cloneRepo vcsHg vcsTestDriverHg
124+
. WithBranchingSupport
125+
108126
prop_syncRepos_git :: RepoDirSet -> SyncTargetIterations -> PrngSeed
109127
-> BranchingRepoRecipe -> Property
110128
prop_syncRepos_git destRepoDirs syncTargetSetIterations seed =
@@ -130,6 +148,14 @@ prop_syncRepos_pijul destRepoDirs syncTargetSetIterations seed =
130148
destRepoDirs syncTargetSetIterations seed
131149
. WithBranchingSupport
132150

151+
prop_syncRepos_hg :: RepoDirSet -> SyncTargetIterations -> PrngSeed
152+
-> BranchingRepoRecipe -> Property
153+
prop_syncRepos_hg destRepoDirs syncTargetSetIterations seed =
154+
ioProperty
155+
. prop_syncRepos vcsHg vcsTestDriverHg
156+
destRepoDirs syncTargetSetIterations seed
157+
. WithBranchingSupport
158+
133159
-- ------------------------------------------------------------
134160
-- * General test setup
135161
-- ------------------------------------------------------------
@@ -755,3 +781,46 @@ vcsTestDriverPijul verbosity vcs repoRoot =
755781
}
756782
pijul = runProgramInvocation verbosity . gitInvocation
757783
pijul' = getProgramInvocationOutput verbosity . gitInvocation
784+
785+
vcsTestDriverHg :: Verbosity -> VCS ConfiguredProgram
786+
-> FilePath -> VCSTestDriver
787+
vcsTestDriverHg verbosity vcs repoRoot =
788+
VCSTestDriver {
789+
vcsVCS = vcs
790+
791+
, vcsRepoRoot = repoRoot
792+
793+
, vcsIgnoreFiles = Set.empty
794+
795+
, vcsInit =
796+
hg $ ["init"] ++ verboseArg
797+
798+
, vcsAddFile = \_ filename ->
799+
hg ["add", filename]
800+
801+
, vcsCommitChanges = \_state -> do
802+
hg $ [ "--user='A <[email protected]>'"
803+
, "commit", "--message=a patch"
804+
] ++ verboseArg
805+
commit <- hg' ["log", "--template='{node}\\n' -l1"]
806+
let commit' = takeWhile (not . isSpace) commit
807+
return (Just commit')
808+
809+
, vcsTagState = \_ tagname ->
810+
hg ["tag", "--force", tagname]
811+
812+
, vcsSwitchBranch = \RepoState{allBranches} branchname -> do
813+
unless (branchname `Map.member` allBranches) $
814+
hg ["branch", branchname]
815+
hg $ ["checkout", branchname] ++ verboseArg
816+
817+
, vcsCheckoutTag = Left $ \tagname ->
818+
hg $ ["checkout", "--rev", tagname] ++ verboseArg
819+
}
820+
where
821+
hgInvocation args = (programInvocation (vcsProgram vcs) args) {
822+
progInvokeCwd = Just repoRoot
823+
}
824+
hg = runProgramInvocation verbosity . hgInvocation
825+
hg' = getProgramInvocationOutput verbosity . hgInvocation
826+
verboseArg = [ "--quiet" | verbosity < Verbosity.normal ]

0 commit comments

Comments
 (0)