Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions git.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ const char* git_Describe() {
const char* git_Branch() {
return "@GIT_BRANCH@";
}
const char* git_CommitShort() {
return "@GIT_SHORT@";
}
7 changes: 7 additions & 0 deletions git.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions git_watcher.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down