diff --git a/git.c.in b/git.c.in index a26d27c..b26ec0f 100644 --- a/git.c.in +++ b/git.c.in @@ -30,3 +30,6 @@ const char* git_Describe() { const char* git_Branch() { return "@GIT_BRANCH@"; } +const char* git_CommitShort() { + return "@GIT_SHORT@"; +} diff --git a/git.h b/git.h index 91ce40b..2030aa7 100644 --- a/git.h +++ b/git.h @@ -52,6 +52,9 @@ const char* git_Describe(); /// The symbolic reference tied to HEAD. const char* git_Branch(); +/// The commit short SHA1. +const char* git_CommitShort(); + GIT_VERSION_TRACKING_EXTERN_C_END #undef GIT_VERSION_TRACKING_EXTERN_C_BEGIN #undef GIT_VERSION_TRACKING_EXTERN_C_END @@ -143,6 +146,10 @@ inline const StringOrView Branch() { static const StringOrView kValue = internal::InitString(git_Branch()); return kValue; } +inline const StringOrView CommitShort() { + static const StringOrView kValue = internal::InitString(git_CommitShort()); + return kValue; +} } // namespace git diff --git a/git_watcher.cmake b/git_watcher.cmake index 32313a3..955bf1a 100644 --- a/git_watcher.cmake +++ b/git_watcher.cmake @@ -105,6 +105,7 @@ set(_state_variable_names GIT_COMMIT_BODY GIT_DESCRIBE GIT_BRANCH + GIT_SHORT # >>> # 1. Add the name of the additional git variable you're interested in monitoring # to this list. @@ -242,6 +243,14 @@ function(GetGitState _working_dir) set(ENV{GIT_BRANCH} "${output}") endif() + # Get output of git describe + RunGitCommand(rev-parse --short ${object}) + if(NOT exit_code EQUAL 0) + set(ENV{GIT_SHORT} "unknown") + else() + set(ENV{GIT_SHORT} "${output}") + endif() + # >>> # 2. Additional git properties can be added here via the # "execute_process()" command. Be sure to set them in