From b6772764ff5e15b63df10c5a59e8926a3a404ab3 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 28 Nov 2019 16:36:26 +0300 Subject: Fix bundled git running other git as a child on Windows --- bpkg/fetch-git.cxx | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'bpkg') 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 (args)...); } catch (const process_error& e) -- cgit v1.1