From 159845050de0e18690739521a8e0585f00e46a10 Mon Sep 17 00:00:00 2001 From: Josh Essman Date: Tue, 22 Dec 2020 12:05:28 -0600 Subject: [PATCH] feat: append -dirty to hashcode for dirty working tree --- RELEASE-NOTES.md | 1 + cmake/BLTGitMacros.cmake | 5 +++-- docs/api/git.rst | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 0955cc930..553e1d21b 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -41,6 +41,7 @@ The project release numbers follow [Semantic Versioning](http://semver.org/spec/ user-specified source directories - Code coverage targets leave LCOV-generated files intact for later use; these files will still be removed by ``make clean`` +- ``blt_git_hashcode`` will append a ``-dirty` suffix if the working tree is dirty (modified) ### Fixed - ClangFormat checks now support multiple Python executable names diff --git a/cmake/BLTGitMacros.cmake b/cmake/BLTGitMacros.cmake index 051ef0888..c108a196d 100644 --- a/cmake/BLTGitMacros.cmake +++ b/cmake/BLTGitMacros.cmake @@ -235,10 +235,11 @@ macro(blt_git_hashcode) endif() ## set target ref + ## match nothing to ensure that a tag isn't added if ( NOT DEFINED arg_ON_BRANCH ) - set(git_cmd rev-parse --short HEAD ) + set(git_cmd describe --match='$^' --always --dirty ) else() - set(git_cmd rev-parse --short ${arg_ON_BRANCH} ) + set(git_cmd describe --match='$^' --always ${arg_ON_BRANCH} ) endif() blt_git( SOURCE_DIR ${git_dir} diff --git a/docs/api/git.rst b/docs/api/git.rst index dade2986d..699434ddf 100644 --- a/docs/api/git.rst +++ b/docs/api/git.rst @@ -167,6 +167,9 @@ branch. In addition, the caller may specify the target Git repository using the SOURCE_DIR argument. Otherwise, if SOURCE_DIR is not specified, the macro will use ${CMAKE_CURRENT_SOURCE_DIR}. +If ON_BRANCH is not specified and the current working tree is dirty (e.g., +files have been modified), then ``-dirty`` will be appended to the HASHCODE. + A return code for the Git command is returned to the caller via the CMake variable provided with the RETURN_CODE argument. A non-zero return code indicates that an error has occured. @@ -180,4 +183,3 @@ indicates that an error has occured. message( FATAL_ERROR "blt_git_hashcode failed!" ) endif() message( STATUS "sha1=${sha1}" ) -