summaryrefslogtreecommitdiff
path: root/src/Version/Git.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-04-25 22:17:58 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2023-04-25 22:17:58 +0200
commit780fc8894379f28af0f03bc27c3a41aca8c95b5a (patch)
treee5bdc1db78df4a58c27a73b8fea675eb5c9328a4 /src/Version/Git.hs
parent649ba09db13caea5de5d179c538b8a2945a9a69d (diff)
Command-line option to report version
Diffstat (limited to 'src/Version/Git.hs')
-rw-r--r--src/Version/Git.hs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Version/Git.hs b/src/Version/Git.hs
new file mode 100644
index 0000000..fcd54a0
--- /dev/null
+++ b/src/Version/Git.hs
@@ -0,0 +1,32 @@
+module Version.Git (
+ tGitVersion,
+) where
+
+import Language.Haskell.TH
+import Language.Haskell.TH.Syntax
+import Language.Haskell.TH.Syntax.Compat
+
+import System.Directory
+import System.Exit
+import System.Process
+
+tGitVersion :: SpliceQ (Maybe String)
+tGitVersion = unsafeSpliceCoerce $ do
+ let git args = do
+ (ExitSuccess, out, _) <- readCreateProcessWithExitCode
+ (proc "git" $ [ "--git-dir=./.git", "--work-tree=." ] ++ args) ""
+ return $ lines out
+
+ mbver <- runIO $ do
+ doesPathExist "./.git" >>= \case
+ False -> return Nothing
+ True -> do
+ desc:_ <- git [ "describe", "--always", "--dirty= (dirty)" ]
+ files <- git [ "ls-files" ]
+ return $ Just (desc, files)
+
+ case mbver of
+ Just (_, files) -> mapM_ addDependentFile files
+ Nothing -> return ()
+
+ lift (fst <$> mbver :: Maybe String)