diff options
Diffstat (limited to 'bpkg/fetch-git.cxx')
-rw-r--r-- | bpkg/fetch-git.cxx | 27 |
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) |