{-# OPTIONS_GHC -Wunused-imports #-}

{-# LANGUAGE CPP             #-}
{-# LANGUAGE TemplateHaskell #-}

{-# OPTIONS_GHC -Wno-overlapping-patterns #-}

module Agda.VersionCommit where

#ifdef VERSION_WITH_GIT_HASH
import Development.GitRev
#endif

import Agda.Version

-- | Agda's version suffixed with the git commit hash.
versionWithCommitInfo :: String
versionWithCommitInfo :: [Char]
versionWithCommitInfo = [Char]
version [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char] -> ([Char] -> [Char]) -> Maybe [Char] -> [Char]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Char]
"" ([Char]
"-" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++) Maybe [Char]
commitInfo

-- | Information about current git commit, generated at compile time.
commitInfo :: Maybe String
#ifdef VERSION_WITH_GIT_HASH
commitInfo
  | hash == "UNKNOWN" = Nothing
  | otherwise         = Just $ abbrev hash ++ dirty
  where
    hash = $(gitHash)

    -- Check if any tracked files have uncommitted changes
    dirty | $(gitDirtyTracked) = "-dirty"
          | otherwise          = ""

    -- Abbreviate a commit hash while keeping it unambiguous
    abbrev = take 7
#else
commitInfo :: Maybe [Char]
commitInfo = Maybe [Char]
forall a. Maybe a
Nothing
#endif