diff options
Diffstat (limited to 'app/Git.hs')
-rw-r--r-- | app/Git.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/app/Git.hs b/app/Git.hs new file mode 100644 index 0000000..57fffdc --- /dev/null +++ b/app/Git.hs @@ -0,0 +1,15 @@ +module Git (withWorkingTree) where + +import Control.Exception (finally) +import Data.Text (Text) +import Process (proc, sh_) +import System.Directory (createDirectoryIfMissing) +import System.FilePath (dropTrailingPathSeparator, takeDirectory) + +-- | Runs an IO-action within a working tree. +withWorkingTree :: FilePath -> Text -> IO a -> IO a +withWorkingTree path hash action = do + createDirectoryIfMissing True (takeDirectory (dropTrailingPathSeparator path)) + sh_ $ proc "git worktree add --quiet --detach % %" path hash + action `finally` do + sh_ $ proc "git worktree remove --force %" path |