aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-11-28 16:36:26 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-11-28 17:38:32 +0300
commitb6772764ff5e15b63df10c5a59e8926a3a404ab3 (patch)
tree4188d994b9cfaea7b63b178c233a2c29c48480c8
parent4f5e6f8bdaf335ef3d3881f5ef175128de97d6ea (diff)
Fix bundled git running other git as a child on Windows
-rw-r--r--bpkg/fetch-git.cxx27
1 files changed, 26 insertions, 1 deletions
diff --git a/bpkg/fetch-git.cxx b/bpkg/fetch-git.cxx
index 00b925b..afb7a26 100644
--- a/bpkg/fetch-git.cxx
+++ b/bpkg/fetch-git.cxx
@@ -211,13 +211,38 @@ namespace bpkg
}
}
+ // On startup git prepends the PATH environment variable value with the
+ // computed directory path where its sub-programs are supposedly located
+ // (--exec-path option, GIT_EXEC_PATH environment variable, etc; see
+ // cmd_main() in git's git.c for details).
+ //
+ // Then, when git needs to run itself or one of its components as a
+ // child process, it resolves the full executable path searching in
+ // directories listed in PATH (see locate_in_PATH() in git's
+ // run-command.c for details).
+ //
+ // On Windows we install git and its components into a place where it is
+ // not expected to be, which results in the wrong path in PATH as set by
+ // git (for example, c:/build2/libexec/git-core) which in turn may lead
+ // to running some other git that appear in the PATH variable. To
+ // prevent this we pass the git's exec directory via the --exec-path
+ // option explicitly.
+ //
+ string ep;
+ process_path pp (process::path_search (co.git (), true /* init */));
+
+#ifdef _WIN32
+ ep = "--exec-path=" + pp.effect.directory ().string ();
+#endif
+
return process_start_callback ([] (const char* const args[], size_t n)
{
if (verb >= 2)
print_process (args, n);
},
0 /* stdin */, out, err,
- process_env (co.git (), *unset_vars),
+ process_env (pp, *unset_vars),
+ !ep.empty () ? ep.c_str () : nullptr,
forward<A> (args)...);
}
catch (const process_error& e)