From e6b5e4339a8674cb83449e11f3e8230e897d908c Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Wed, 22 Nov 2023 02:52:55 +0100 Subject: [PATCH] Sanitize (unsupported) GIT_* environment variables Prevent passing environment variables to git.exe that are currently unsupported in TortoiseGit/libgit2 to prevent inconsistencies (cf. issue #4029 and issue #3852) cf. https://github.com/git-for-windows/build-extra/pull/529 Signed-off-by: Sven Strickroth --- src/Changelog.txt | 1 + src/Git/Git.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Changelog.txt b/src/Changelog.txt index 6acd89771..7888e0c2f 100644 --- a/src/Changelog.txt +++ b/src/Changelog.txt @@ -13,6 +13,7 @@ Released: unreleased * Fixed issue #4086: ResolveDlg: Merge conflict file gets changed after fixing merge and pressing Resolve * Fixed issue #3917: Git not getting LFS files (SSHAskPass not showing) * Fixed issue #4083: TortoiseGitMerge: Infinite loop when diff file has only 1 line and perform "Redo" + * Sanitize GIT_* environment variables to prevent passing environment variables to git.exe that are currently unsupported in TortoiseGit/libgit2 to prevent inconsistencies = Release 2.15.0 = Released: 2023-10-03 diff --git a/src/Git/Git.cpp b/src/Git/Git.cpp index 15faa1d9d..a29030d3c 100644 --- a/src/Git/Git.cpp +++ b/src/Git/Git.cpp @@ -2140,6 +2140,24 @@ BOOL CGit::CheckMsysGitDir(BOOL bFallback) m_Environment.SetEnv(L"TGIT_INITIATED_CALL", L"1"); + // Sanitize GIT_* environment variables, cf. https://github.com/git-for-windows/build-extra/pull/529 + m_Environment.SetEnv(L"GIT_INDEX_FILE", nullptr); + m_Environment.SetEnv(L"GIT_INDEX_VERSION", nullptr); + m_Environment.SetEnv(L"GIT_OBJECT_DIRECTORY", nullptr); + m_Environment.SetEnv(L"GIT_ALTERNATE_OBJECT_DIRECTORIES", nullptr); + m_Environment.SetEnv(L"GIT_DIR", nullptr); + m_Environment.SetEnv(L"GIT_WORK_TREE", nullptr); + m_Environment.SetEnv(L"GIT_NAMESPACE", nullptr); + m_Environment.SetEnv(L"GIT_CEILING_DIRECTORIES", nullptr); + m_Environment.SetEnv(L"GIT_DISCOVERY_ACROSS_FILESYSTEM", nullptr); + m_Environment.SetEnv(L"GIT_COMMON_DIR", nullptr); + m_Environment.SetEnv(L"GIT_DEFAULT_HASH", nullptr); + m_Environment.SetEnv(L"GIT_CONFIG", nullptr); + m_Environment.SetEnv(L"GIT_CONFIG_GLOBAL", nullptr); + m_Environment.SetEnv(L"GIT_CONFIG_SYSTEM", nullptr); + m_Environment.SetEnv(L"GIT_CONFIG_NOSYSTEM", nullptr); + m_Environment.SetEnv(L"GIT_CONFIG_COUNT", nullptr); + // Git for Windows 2.10.1 and 2.10.2 require LC_ALL to be set, see https://tortoisegit.org/issue/2859 and https://github.com/git-for-windows/git/issues/945, // because MSys2 changed the default to "ASCII". SO, make sure we have a proper default set if (m_Environment.GetEnv(L"LC_ALL").IsEmpty()) -- 2.11.4.GIT