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

#if __GLASGOW_HASKELL__ >= 900
{-# OPTIONS_GHC -Wno-overlapping-patterns #-}
#endif

module Agda.VersionCommit where

import Development.GitRev

import Agda.Version

versionWithCommitInfo :: String
versionWithCommitInfo :: [Char]
versionWithCommitInfo = [Char]
version forall a. [a] -> [a] -> [a]
++ forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Char]
"" ([Char]
"-" forall a. [a] -> [a] -> [a]
++) Maybe [Char]
commitInfo

-- | Information about current git commit, generated at compile time
commitInfo :: Maybe String
commitInfo :: Maybe [Char]
commitInfo
  | [Char]
hash forall a. Eq a => a -> a -> Bool
== [Char]
"UNKNOWN" = forall a. Maybe a
Nothing
  | Bool
otherwise         = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall {a}. [a] -> [a]
abbrev [Char]
hash forall a. [a] -> [a] -> [a]
++ [Char]
dirty
  where
    hash :: [Char]
hash = $(gitHash)

    -- Check if any tracked files have uncommitted changes
    dirty :: [Char]
dirty | $(gitDirtyTracked) = [Char]
"-dirty"
          | Bool
otherwise          = [Char]
""

    -- Abbreviate a commit hash while keeping it unambiguous
    abbrev :: [a] -> [a]
abbrev = forall a. Int -> [a] -> [a]
take Int
7