From ee317adc7e42a360274710c434bba7daa63582dc Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Thu, 29 Aug 2013 15:34:48 +0200
Subject: [PATCH] Better git finding on Windows.

---
 scripts/cmake/Find.cmake             |  7 +++++++
 scripts/cmake/cmake/FindGitHub.cmake | 11 +++++------
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/scripts/cmake/Find.cmake b/scripts/cmake/Find.cmake
index 906d048f67e..2cc014e3b5e 100644
--- a/scripts/cmake/Find.cmake
+++ b/scripts/cmake/Find.cmake
@@ -30,6 +30,13 @@ FIND_PACKAGE(PythonInterp QUIET)
 FIND_PACKAGE(GitHub)
 
 FIND_PROGRAM(GIT_TOOL_PATH git HINTS ${GITHUB_BIN_DIR} DOC "The git command line interface")
+IF(NOT GIT_TOOL_PATH)
+	IF(WIN32)
+		MESSAGE(FATAL_ERROR "Git not found! Please install GitHub for Windows or Git!")
+	ELSE()
+		MESSAGE(FATAL_ERROR "Git not found but is required!")
+	ENDIF()
+ENDIF()
 
 # Find bash itself ...
 FIND_PROGRAM(BASH_TOOL_PATH bash
diff --git a/scripts/cmake/cmake/FindGitHub.cmake b/scripts/cmake/cmake/FindGitHub.cmake
index f45cd21a290..b8d2764eb14 100644
--- a/scripts/cmake/cmake/FindGitHub.cmake
+++ b/scripts/cmake/cmake/FindGitHub.cmake
@@ -13,25 +13,24 @@ IF(WIN32 AND NOT GITHUB_FOUND)
 	FIND_PATH(
 		GITHUB_DIR
 		shell.ps1
-		PATHS $ENV{LOCALAPPDATA}/GitHub
+		PATHS $ENV{LOCALAPPDATA}/GitHub $ENV{GitHub_DIR}
 		NO_DEFAULT_PATH
 	)
 
 	IF(GITHUB_DIR)
 
-		FILE(TO_NATIVE_PATH ${GITHUB_DIR} GITHUB_WIN_DIR)
 		EXECUTE_PROCESS (
-			COMMAND cmd /c "cd ${GITHUB_WIN_DIR}/PortableGit* & cd"
+			COMMAND cmd /c "cd ${GITHUB_DIR}/PortableGit*/bin & cd"
 			OUTPUT_VARIABLE PORTABLE_GIT_WIN_DIR
 		)
 
 		IF(PORTABLE_GIT_WIN_DIR)
 			STRING(STRIP ${PORTABLE_GIT_WIN_DIR} PORTABLE_GIT_WIN_DIR)
-			FILE(TO_CMAKE_PATH ${PORTABLE_GIT_WIN_DIR} PORTABLE_GIT_DIR)
+			FILE(TO_CMAKE_PATH ${PORTABLE_GIT_WIN_DIR} PORTABLE_GIT_WIN_DIR)
 			SET(GITHUB_FOUND ON CACHE BOOL "Was GitHub for Windows found?")
-			SET(GITHUB_BIN_DIR ${PORTABLE_GIT_DIR}/bin CACHE PATH "The path to the GitHub for Windows binaries.")
+			SET(GITHUB_BIN_DIR ${PORTABLE_GIT_WIN_DIR} CACHE PATH "The path to the GitHub for Windows binaries." FORCE)
 			MESSAGE(STATUS "GitHub for Windows found.")
 		ENDIF()
 
 	ENDIF()
-ENDIF()
\ No newline at end of file
+ENDIF()
-- 
GitLab