Skip to content

Commit

Permalink
CMake: fix 'sudo make [install]' from a checkout owned by a non-root …
Browse files Browse the repository at this point in the history
…user
  • Loading branch information
rouault committed May 5, 2022
1 parent 08713ef commit d0c8b95
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmake/modules/thirdparty/GetGitRevisionDescription.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ function(get_git_head_revision _refspecvar _hashvar _repo_dir)
OUTPUT_STRIP_TRAILING_WHITESPACE)

if(NOT res EQUAL 0)
return()
# git rev-parse can fail if run as root (e.g "sudo make install")
# on a git repo owned by another user
if(EXISTS ${_repo_dir}/.git/HEAD)
set(GIT_DIR ${_repo_dir}/.git)
else()
return()
endif()
endif()

get_filename_component(GIT_DIR "${GIT_DIR}" ABSOLUTE BASE_DIR "${_repo_dir}")
Expand Down

0 comments on commit d0c8b95

Please sign in to comment.