Skip to content

Commit

Permalink
Remove Git.root and use gitlib.
Browse files Browse the repository at this point in the history
  • Loading branch information
alunduil committed Sep 22, 2024
1 parent 0ae10a1 commit af6e902
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "",
"postCreateCommand": "sudo apt-get update && sudo apt-get install -y libicu-dev",
// Configure tool-specific properties.
"customizations": {
"vscode": {
Expand Down
2 changes: 1 addition & 1 deletion lib/initialise/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import System.Directory.Extra (createDirectoryIfMissing, removeDirectoryRecursiv
import System.FilePath (replaceBaseName, (</>))
import Prelude hiding (concat, head, readFile, unlines, writeFile)

#if __GLASGOW_HASKELL__ < 908
#if __GLASGOW_HASKELL__ < 904
import Text.Parsec.Error (ParseError)
instance Exception ParseError
#endif
Expand Down
8 changes: 0 additions & 8 deletions lib/initialise/Git.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Git
( config,
root,
)
where

Expand All @@ -14,10 +13,3 @@ config key = do
case output of
Just (x :| _) -> pure $ pack x
Nothing -> fail $ "`git config " <> unpack key <> "` returned no output"

root :: IO Text
root = do
output <- nonEmpty . lines <$> readProcess "git" ["rev-parse", "--show-toplevel"] ""
case output of
Just (x :| _) -> pure $ pack x
Nothing -> fail "`git rev-parse --show-toplevel` returned no output"
4 changes: 3 additions & 1 deletion templatise.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ library initialise-library
, http-conduit ^>=2.3.8.3
, regex-tdfa ^>=1.3.2.2

if impl(ghc <9.8)
if impl(ghc <9.4)
build-depends: parsec ^>=3.1.15.0

hs-source-dirs: lib/initialise
Expand All @@ -96,13 +96,15 @@ test-suite initialise-test
main-is: Main.hs
build-depends:
, directory ^>=1.3.6.2
, gitlib-libgit2 ^>=3.1.2.1
, hspec ^>=2.11.4
, initialise-library
, tasty ^>=1.4.3 || ^>=1.5
, tasty-golden ^>=2.3.5
, tasty-hspec ^>=1.2.0.4
, temporary ^>=1.3

--, gitlib ^>=3.1.3
other-modules:
CabalGolden
DefaultsSpec
Expand Down
11 changes: 9 additions & 2 deletions test/initialise/Hooks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module Hooks (withGitRepo, withProjectCopy) where
import Control.Applicative ((<|>))
import Control.Monad (void)
import Data.Text (unpack)
import Git (root)
import Git (repositoryPath)
import Git.Libgit2 (defaultRepositoryOptions, openRepository)
import System.Directory (getCurrentDirectory, withCurrentDirectory)
import System.FilePath (takeFileName, (</>))
import System.IO.Temp (withSystemTempDirectory)
Expand All @@ -22,7 +23,13 @@ withGitRepo action =
withProjectCopy :: (FilePath -> IO ()) -> IO ()
withProjectCopy action = do
withSystemTempDirectory "initialise" $ \p -> do
r <- unpack <$> root <|> getCurrentDirectory
r <- root
void $ readProcess "cp" ["-a", r, p] ""
let p' = p </> takeFileName r
withCurrentDirectory p' $ action p'

root :: IO String
root = do
cwd <- getCurrentDirectory
repo <- openRepository defaultRepositoryOptions cwd
either cwd (liftIO . repositoryPath) repo

0 comments on commit af6e902

Please sign in to comment.