mirror of
https://github.com/git/git.git
synced 2026-01-31 13:03:13 +00:00
mingw: unset PERL5LIB by default
Git for Windows ships with its own Perl interpreter, and insists on using it, so it will most likely wreak havoc if PERL5LIB is set before launching Git. Let's just unset that environment variables when spawning processes. To make this feature extensible (and overrideable), there is a new config setting `core.unsetenvvars` that allows specifying a comma-separated list of names to unset before spawning processes. Reported by Gabriel Fuhrmann. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
@@ -775,6 +775,12 @@ core.longpaths::
|
||||
(msys, bash, tcl, perl...). Only enable this if you know what you're
|
||||
doing and are prepared to live with a few quirks.
|
||||
|
||||
core.unsetenvvars::
|
||||
EXPERIMENTAL, Windows-only: comma-separated list of environment
|
||||
variables' names that need to be unset before spawning any other
|
||||
process. Defaults to `PERL5LIB` to account for the fact that Git
|
||||
for Windows insists on using its own Perl interpreter.
|
||||
|
||||
core.createObject::
|
||||
You can set this to 'link', in which case a hardlink followed by
|
||||
a delete of the source are used to make sure that object creation
|
||||
|
||||
@@ -238,6 +238,7 @@ enum hide_dotfiles_type {
|
||||
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
|
||||
int core_fscache;
|
||||
int core_long_paths;
|
||||
static char *unset_environment_variables;
|
||||
|
||||
int mingw_core_config(const char *var, const char *value)
|
||||
{
|
||||
@@ -259,6 +260,12 @@ int mingw_core_config(const char *var, const char *value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp(var, "core.unsetenvvars")) {
|
||||
free(unset_environment_variables);
|
||||
unset_environment_variables = xstrdup(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1432,6 +1439,27 @@ static wchar_t *make_environment_block(char **deltaenv)
|
||||
|
||||
#endif
|
||||
|
||||
static void do_unset_environment_variables(void)
|
||||
{
|
||||
static int done;
|
||||
char *p = unset_environment_variables;
|
||||
|
||||
if (done || !p)
|
||||
return;
|
||||
done = 1;
|
||||
|
||||
for (;;) {
|
||||
char *comma = strchr(p, ',');
|
||||
|
||||
if (comma)
|
||||
*comma = '\0';
|
||||
unsetenv(p);
|
||||
if (!comma)
|
||||
break;
|
||||
p = comma + 1;
|
||||
}
|
||||
}
|
||||
|
||||
struct pinfo_t {
|
||||
struct pinfo_t *next;
|
||||
pid_t pid;
|
||||
@@ -1450,9 +1478,12 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
|
||||
wchar_t wcmd[MAX_PATH], wdir[MAX_PATH], *wargs, *wenvblk = NULL;
|
||||
unsigned flags = CREATE_UNICODE_ENVIRONMENT;
|
||||
BOOL ret;
|
||||
HANDLE cons;
|
||||
|
||||
do_unset_environment_variables();
|
||||
|
||||
/* Determine whether or not we are associated to a console */
|
||||
HANDLE cons = CreateFile("CONOUT$", GENERIC_WRITE,
|
||||
cons = CreateFile("CONOUT$", GENERIC_WRITE,
|
||||
FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (cons == INVALID_HANDLE_VALUE) {
|
||||
@@ -3035,6 +3066,8 @@ int msc_startup(int argc, wchar_t **w_argv, wchar_t **w_env)
|
||||
/* fix Windows specific environment settings */
|
||||
setup_windows_environment();
|
||||
|
||||
unset_environment_variables = xstrdup("PERL5LIB");
|
||||
|
||||
/* initialize critical section for waitpid pinfo_t list */
|
||||
InitializeCriticalSection(&pinfo_cs);
|
||||
InitializeCriticalSection(&phantom_symlinks_cs);
|
||||
@@ -3111,6 +3144,8 @@ void mingw_startup(void)
|
||||
/* fix Windows specific environment settings */
|
||||
setup_windows_environment();
|
||||
|
||||
unset_environment_variables = xstrdup("PERL5LIB");
|
||||
|
||||
/*
|
||||
* Avoid a segmentation fault when cURL tries to set the CHARSET
|
||||
* variable and putenv() barfs at our nedmalloc'ed environment.
|
||||
|
||||
30
t/t0028-core-unsetenvvars.sh
Executable file
30
t/t0028-core-unsetenvvars.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
|
||||
test_description='test the Windows-only core.unsetenvvars setting'
|
||||
|
||||
. ./test-lib.sh
|
||||
|
||||
if ! test_have_prereq MINGW
|
||||
then
|
||||
skip_all='skipping Windows-specific tests'
|
||||
test_done
|
||||
fi
|
||||
|
||||
test_expect_success 'setup' '
|
||||
mkdir -p "$TRASH_DIRECTORY/.git/hooks" &&
|
||||
write_script "$TRASH_DIRECTORY/.git/hooks/pre-commit" <<-\EOF
|
||||
echo $HOBBES >&2
|
||||
EOF
|
||||
'
|
||||
|
||||
test_expect_success 'core.unsetenvvars works' '
|
||||
HOBBES=Calvin &&
|
||||
export HOBBES &&
|
||||
git commit --allow-empty -m with 2>err &&
|
||||
grep Calvin err &&
|
||||
git -c core.unsetenvvars=FINDUS,HOBBES,CALVIN \
|
||||
commit --allow-empty -m without 2>err &&
|
||||
! grep Calvin err
|
||||
'
|
||||
|
||||
test_done
|
||||
Reference in New Issue
Block a user