From ec2d9a0f6f5a67a8c725e73d33a8e5d4fea65203 Mon Sep 17 00:00:00 2001 From: Thomas Braun Date: Mon, 14 Oct 2024 12:12:46 +0200 Subject: [PATCH] CreateMiesVersion: Also try git from PATH Accompanying fix for 13e8467c7 (GetPossiblePathsToGit: Fix paths on windows, 2024-09-27) as we now fallback to use git from PATH if none of the candidate locations is usable. --- .../MIES_GlobalStringAndVariableAccess.ipf | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/Packages/MIES/MIES_GlobalStringAndVariableAccess.ipf b/Packages/MIES/MIES_GlobalStringAndVariableAccess.ipf index 6fa15ad0a0..5a9c17e0c7 100644 --- a/Packages/MIES/MIES_GlobalStringAndVariableAccess.ipf +++ b/Packages/MIES/MIES_GlobalStringAndVariableAccess.ipf @@ -196,6 +196,7 @@ static Function/S CreateMiesVersion() string path, topDir, version, gitPath string gitDir, fullVersionPath variable refNum + variable ret = 1 // set path to the toplevel directory in the mies folder structure path = ParseFilePath(1, FunctionPath(""), ":", 1, 2) @@ -213,9 +214,14 @@ static Function/S CreateMiesVersion() continue endif - ExecuteGitForMIESVersion(gitPath, gitDir, topDir, fullVersionPath) + ret = ExecuteGitForMIESVersion(gitPath, gitDir, topDir, fullVersionPath) break endfor + + if(ret) + // none of the candidates worked, fallback to use git from PATH + ExecuteGitForMIESVersion("git", gitDir, topDir, fullVersionPath) + endif endif open/R/Z refNum as fullVersionPath @@ -248,19 +254,21 @@ End /// @brief Run some git commands to generate version.txt from the MIES repository /// -/// @param gitPath full path to a git binary on the system +/// @param gitPath full path to a git binary on the system or plain git for using the one in PATH /// @param gitDir full path to .git in the MIES repository /// @param topDir full path to the toplevel folder of the MIES repository -static Function ExecuteGitForMIESVersion(string gitPath, string gitDir, string topDir, string fullVersionPath) +/// +/// @return zero on success, aborts on failure +static Function ExecuteGitForMIESVersion(string gitPathOrName, string gitDir, string topDir, string fullVersionPath) string cmd, userName - gitPath = HFSPathToNative(gitPath) - gitDir = HFSPathToNative(gitDir) - topDir = HFSPathToNative(topDir) + gitPathOrName = HFSPathToNative(gitPathOrName) + gitDir = HFSPathToNative(gitDir) + topDir = HFSPathToNative(topDir) // git is installed, try to regenerate version.txt - DEBUGPRINT("Found git at: ", str = gitPath) + DEBUGPRINT("Found git at: ", str = gitPathOrName) // delete the old version.txt so that we can be sure to get the correct one afterwards DeleteFile/Z fullVersionPath @@ -269,7 +277,7 @@ static Function ExecuteGitForMIESVersion(string gitPath, string gitDir, string t #if defined(WINDOWS) // explanation: // cmd /C " --git-dir= describe redirect everything into /version.txt" - sprintf cmd, "cmd.exe /C \"\"%s\" --git-dir=\"%s\" describe --always --tags --match \"Release_*\" > \"%sversion.txt\" 2>&1\"", gitPath, gitDir, topDir + sprintf cmd, "cmd.exe /C \"\"%s\" --git-dir=\"%s\" describe --always --tags --match \"Release_*\" > \"%sversion.txt\" 2>&1\"", gitPathOrName, gitDir, topDir DEBUGPRINT("Cmd to execute: ", str = cmd) ExecuteScriptText/B/Z cmd ASSERT(!V_flag, "We have git installed but could not regenerate version.txt") @@ -279,7 +287,7 @@ static Function ExecuteGitForMIESVersion(string gitPath, string gitDir, string t ExecuteScriptText/B/Z cmd ASSERT(!V_flag, "We have git installed but could not regenerate version.txt") - sprintf cmd, "cmd.exe /C \"\"%s\" --git-dir=\"%s\" log -1 --pretty=format:%%cI%%n >> \"%sversion.txt\" 2>&1\"", gitPath, gitDir, topDir + sprintf cmd, "cmd.exe /C \"\"%s\" --git-dir=\"%s\" log -1 --pretty=format:%%cI%%n >> \"%sversion.txt\" 2>&1\"", gitPathOrName, gitDir, topDir DEBUGPRINT("Cmd to execute: ", str = cmd) ExecuteScriptText/B/Z cmd ASSERT(!V_flag, "We have git installed but could not regenerate version.txt") @@ -292,12 +300,12 @@ static Function ExecuteGitForMIESVersion(string gitPath, string gitDir, string t // git submodule status can not be used here as submodule is currently a sh script and executing that with --git-dir does not work // but we can use the helper command which outputs a slightly uglier version, but is much faster // the submodule helper is shipped with git 2.7 and later, therefore its failed execution is not fatal - sprintf cmd, "cmd.exe /C \"\"%s\" --git-dir=\"%s\" submodule--helper status >> \"%sversion.txt\" 2>&1\"", gitPath, gitDir, topDir + sprintf cmd, "cmd.exe /C \"\"%s\" --git-dir=\"%s\" submodule--helper status >> \"%sversion.txt\" 2>&1\"", gitPathOrName, gitDir, topDir DEBUGPRINT("Cmd to execute: ", str = cmd) ExecuteScriptText/B/Z cmd #elif defined(MACINTOSH) - sprintf cmd, "do shell script \"%s --version\"", gitPath + sprintf cmd, "do shell script \"%s --version\"", gitPathOrName DEBUGPRINT("Cmd to execute: ", str = cmd) ExecuteScriptText/UNQ/Z cmd if(V_flag) @@ -306,7 +314,7 @@ static Function ExecuteGitForMIESVersion(string gitPath, string gitDir, string t break endif - sprintf cmd, "do shell script \"%s --git-dir='%s' describe --always --tags --match 'Release_*' > '%sversion.txt' 2>&1\"", gitPath, gitDir, topDir + sprintf cmd, "do shell script \"%s --git-dir='%s' describe --always --tags --match 'Release_*' > '%sversion.txt' 2>&1\"", gitPathOrName, gitDir, topDir DEBUGPRINT("Cmd to execute: ", str = cmd) ExecuteScriptText/UNQ/Z cmd ASSERT(!V_flag, "We have git installed but could not regenerate version.txt") @@ -316,7 +324,7 @@ static Function ExecuteGitForMIESVersion(string gitPath, string gitDir, string t ExecuteScriptText/UNQ/Z cmd ASSERT(!V_flag, "We have git installed but could not regenerate version.txt") - sprintf cmd, "do shell script \"%s --git-dir='%s' log -1 --pretty=format:%%cI%%n >> '%sversion.txt' 2>&1\"", gitPath, gitDir, topDir + sprintf cmd, "do shell script \"%s --git-dir='%s' log -1 --pretty=format:%%cI%%n >> '%sversion.txt' 2>&1\"", gitPathOrName, gitDir, topDir DEBUGPRINT("Cmd to execute: ", str = cmd) ExecuteScriptText/UNQ/Z cmd ASSERT(!V_flag, "We have git installed but could not regenerate version.txt") @@ -327,12 +335,14 @@ static Function ExecuteGitForMIESVersion(string gitPath, string gitDir, string t ASSERT(!V_flag, "We have git installed but could not regenerate version.txt") // see comment in WINDOWS branch - sprintf cmd, "do shell script \"%s --git-dir='%s' submodule--helper status >> '%sversion.txt' 2>&1\"", gitPath, gitDir, topDir + sprintf cmd, "do shell script \"%s --git-dir='%s' submodule--helper status >> '%sversion.txt' 2>&1\"", gitPathOrName, gitDir, topDir DEBUGPRINT("Cmd to execute: ", str = cmd) ExecuteScriptText/UNQ/Z cmd #else ASSERT(0, "Unsupported OS") #endif + + return 0 End /// @brief Returns the absolute path to the variable `runMode`