Don't look recursively for a .git dir
authorManuel Nickschas <sputnick@quassel-irc.org>
Sun, 16 Mar 2014 21:00:49 +0000 (22:00 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 16 Mar 2014 21:00:49 +0000 (22:00 +0100)
The original GetGitRevisionDescription.cmake script would look for
a .git dir recursively in the parent directories of its invocation;
while a nice feature, it may pick up an unrelated repository if there's
none in the Quassel directory. Because we know exactly where to find
our own .git if it's there at all, we can remove the recursion and
prevent this issue.

cmake/modules/GetGitRevisionDescription.cmake

index aa2ef71..10e3707 100644 (file)
@@ -40,19 +40,12 @@ set(__get_git_revision_description YES)
 get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
 
 function(get_git_head_revision _refspecvar _hashvar)
 get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
 
 function(get_git_head_revision _refspecvar _hashvar)
-       set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
-       set(GIT_DIR "${GIT_PARENT_DIR}/.git")
-       while(NOT EXISTS "${GIT_DIR}")  # .git dir not found, search parent directories
-               set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
-               get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
-               if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
-                       # We have reached the root directory, we are not in git
-                       set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
-                       set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
-                       return()
-               endif()
-               set(GIT_DIR "${GIT_PARENT_DIR}/.git")
-       endwhile()
+       set(GIT_DIR "${CMAKE_SOURCE_DIR}/.git")
+       if(NOT EXISTS "${GIT_DIR}")     # .git dir not found
+               set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
+               set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
+               return()
+       endif()
        # check if this is a submodule
        if(NOT IS_DIRECTORY ${GIT_DIR})
                file(READ ${GIT_DIR} submodule)
        # check if this is a submodule
        if(NOT IS_DIRECTORY ${GIT_DIR})
                file(READ ${GIT_DIR} submodule)