diff --git a/src/Simplex/Messaging/Server/Main/GitCommit.hs b/src/Simplex/Messaging/Server/Main/GitCommit.hs index 03d8691b8..43489083b 100644 --- a/src/Simplex/Messaging/Server/Main/GitCommit.hs +++ b/src/Simplex/Messaging/Server/Main/GitCommit.hs @@ -6,14 +6,25 @@ module Simplex.Messaging.Server.Main.GitCommit ) where import Language.Haskell.TH +import Language.Haskell.TH.Syntax (addDependentFile) import System.Process import Control.Exception +import Control.Monad (filterM) +import System.Directory (doesFileExist) import System.Exit +import System.FilePath (()) gitCommit :: Q Exp -gitCommit = stringE . commit =<< runIO (try $ readProcessWithExitCode "git" ["rev-parse", "HEAD"] "") +gitCommit = + runIO gitHead >>= \case + Right (ExitSuccess, out, _) + | [commit, gitDir] <- lines out -> do + -- without these dependencies GHC recompilation check would not know that the commit changed. + -- HEAD reflog is updated on any HEAD change and, unlike branch ref files, git gc cannot remove it + -- mid-build; it is absent when reflogs are disabled, and addDependentFile fails on a missing file + mapM_ addDependentFile =<< runIO (filterM doesFileExist [gitDir "HEAD", gitDir "logs" "HEAD"]) + stringE commit + _ -> stringE "" where - commit :: Either SomeException (ExitCode, String, String) -> String - commit = \case - Right (ExitSuccess, out, _) -> take 40 out - _ -> "" + gitHead :: IO (Either SomeException (ExitCode, String, String)) + gitHead = try $ readProcessWithExitCode "git" ["rev-parse", "HEAD", "--git-dir"] ""