From fd3a2e967cd3923f8fc63b036cb74a20953c67ba Mon Sep 17 00:00:00 2001 From: Anderson Chauphan Date: Fri, 12 Jan 2024 12:37:17 -0700 Subject: [PATCH] Add commit sha1 input for tribits_generate_commit_info_string (#597) Make tribits_generate_commit_info_string output commit info based on a passed in commit sha1. --- ...ogram_inout.single_repo_one_parent_version.txt | 7 +++++-- .../package_arch/TribitsGitRepoVersionInfo.cmake | 15 +++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_repo_one_parent_version.txt b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_repo_one_parent_version.txt index 3b43f1f3e..9006e223b 100644 --- a/test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_repo_one_parent_version.txt +++ b/test/core/ExamplesUnitTests/configure_git_mockprogram_files/mockprogram_inout.single_repo_one_parent_version.txt @@ -1,6 +1,9 @@ -MOCK_PROGRAM_INPUT: log -1 --pretty=format:%h [%ad] <%ae> +MOCK_PROGRAM_INPUT: log -1 --pretty=format:%H +MOCK_PROGRAM_RETURN: 0 +MOCK_PROGRAM_OUTPUT: a1234tgbhyujkliu126sl12123s +MOCK_PROGRAM_INPUT: log -1 a1234tgbhyujkliu126sl12123s --pretty=format:%h [%ad] <%ae> MOCK_PROGRAM_RETURN: 0 MOCK_PROGRAM_OUTPUT: a1234tgb [Thu Sep 21 19:19:18 2023 -0400] -MOCK_PROGRAM_INPUT: log -1 --pretty=format:%s +MOCK_PROGRAM_INPUT: log -1 a1234tgbhyujkliu126sl12123s --pretty=format:%s MOCK_PROGRAM_RETURN: 0 MOCK_PROGRAM_OUTPUT: This is the git commit summary line diff --git a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake index 68373cca4..d55006368 100644 --- a/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake +++ b/tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake @@ -110,14 +110,14 @@ endfunction() # Run git log to generate a string containing commit sha1, author, date, email # and the commit summary -function(tribits_generate_commit_info_string gitRepoDir +function(tribits_generate_commit_info_string gitRepoDir gitCommitSha1 commitInfoStringOut ) # A) Get commit hash, author, date, and email execute_process( - COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%h [%ad] <%ae>" + COMMAND ${GIT_EXECUTABLE} log -1 ${gitCommitSha1} "--pretty=format:%h [%ad] <%ae>" WORKING_DIRECTORY ${gitRepoDir} RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOut @@ -126,7 +126,7 @@ function(tribits_generate_commit_info_string gitRepoDir if (NOT gitCmndRtn STREQUAL 0) message(FATAL_ERROR "ERROR, ${GIT_EXECUTABLE} command returned ${gitCmndRtn}!=0" - " for SHA1 of repo ${gitRepoDir}!") + " with output '${gitCmndOut}' for sha1 ${gitCommitSha1} of repo ${gitRepoDir}!") set(gitVersionLine "Error, could not get version info!") else() set(gitVersionLine "${gitCmndOut}") @@ -135,7 +135,7 @@ function(tribits_generate_commit_info_string gitRepoDir # B) Get the first 80 chars of the summary message for more info execute_process( - COMMAND ${GIT_EXECUTABLE} log -1 "--pretty=format:%s" + COMMAND ${GIT_EXECUTABLE} log -1 ${gitCommitSha1} "--pretty=format:%s" WORKING_DIRECTORY ${gitRepoDir} RESULT_VARIABLE gitCmndRtn OUTPUT_VARIABLE gitCmndOutput @@ -144,7 +144,7 @@ function(tribits_generate_commit_info_string gitRepoDir if (NOT gitCmndRtn STREQUAL 0) message(FATAL_ERROR "ERROR, ${GIT_EXECUTABLE} command returned ${gitCmndRtn}!=0" - " for SHA1 of repo ${gitRepoDir}!") + " with output '${gitCmndOut}' for sha1 ${gitCommitSha1} of repo ${gitRepoDir}!") set(gitSummaryStr "Error, could not get version summary!") else() set(maxSummaryLen 80) @@ -167,8 +167,11 @@ function(tribits_generate_single_repo_version_string gitRepoDir # A) Get HEAD commit's info + tribits_git_repo_sha1(${gitRepoDir} + gitHeadSha1) + tribits_generate_commit_info_string( - ${gitRepoDir} + ${gitRepoDir} ${gitHeadSha1} headCommitInfoString) set(${repoVersionStringOut} "${headCommitInfoString}" PARENT_SCOPE)