Skip to content

Commit

Permalink
Add commit sha1 input for tribits_generate_commit_info_string (#597)
Browse files Browse the repository at this point in the history
Make tribits_generate_commit_info_string output commit info based on a passed in
commit sha1.
  • Loading branch information
achauphan committed Jan 12, 2024
1 parent 8966263 commit fd3a2e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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] <[email protected]>
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
15 changes: 9 additions & 6 deletions tribits/core/package_arch/TribitsGitRepoVersionInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}")
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit fd3a2e9

Please sign in to comment.