git/list[1] front-page[2] threads[3] people[4] search[5] about
 

BUG: git bash / python interaction with absolute paths as environment variables in Windows

From
LWLeland Weathers <leland@lcweathers.net>
Date
Dec 7, 2021, 03:00 UTC
Message-ID
<CAHeq4YxktibxMBnMLwEq9Nvsgw0UqCrjW2WPcerJCM4mXKxiEw@mail.gmail.com>
Issue: Using Git Bash for Windows (2.34.1-64) and Python 3.9.9, a git
path is incorrectly prepended to environment variables in Python code.

Sample Output of a simple Python script pulling an environment variable - this is the expected output, where Python is given the correct environment variables for both absolute directory paths and non-directory paths - OS should not matter:

(gitfu-XXGUYdp7) C:\Users\Leland\code\gitfu>type foobar.py from os import environ from sys import stdout

stdout.write(f'environ: {environ["TEST_DIR_BROKEN"]}\n') stdout.write(f'environ: {environ["TEST_DIR_WORKING"]}\n') (gitfu-XXGUYdp7) C:\Users\Leland\code\gitfu>echo %TEST_DIR_BROKEN% /foo/bar

(gitfu-XXGUYdp7) C:\Users\Leland\code\gitfu>echo %TEST_DIR_WORKING% foo/bar

(gitfu-XXGUYdp7) C:\Users\Leland\code\gitfu>python foobar.py environ: /foo/bar environ: foo/bar

(gitfu-XXGUYdp7) C:\Users\Leland\code\gitfu>powershell Get-Command python.exe

CommandType Name Version Source ----------- ---- ------- ------ Application python.exe 3.9.915... C:\Users\Leland\.virtualenvs\gitfu-XXGUYdp7\Scripts\python.exe

(gitfu-XXGUYdp7) C:\Users\Leland\code\gitfu>

Sample output when the same set of commands is run in git bash - absolute path has been altered the relative path has not been:

$ cat foobar.py from os import environ from sys import stdout

stdout.write(f'environ: {environ["TEST_DIR_BROKEN"]}\n') stdout.write(f'environ: {environ["TEST_DIR_WORKING"]}\n') Leland@local MINGW64 ~/code/gitfu $ echo $TEST_DIR_BROKEN /foo/bar

Leland@local MINGW64 ~/code/gitfu $ echo $TEST_DIR_WORKING foo/bar

Leland@local MINGW64 ~/code/gitfu $ python foobar.py environ: C:/Users/Leland/AppData/Local/Programs/Git/foo/bar environ: foo/bar

Leland@local MINGW64 ~/code/gitfu $ which python /c/Users/Leland/.virtualenvs/gitfu-XXGUYdp7/Scripts/python

Leland@local MINGW64 ~/code/gitfu $

Is there anything else I'm missing on why the same Python script would read environment variables differently than what is read from Git Bash itself or why the exact same Python code reads the environment variable correctly when run from a command prompt and not in Git Bash?

In both cases I am using the same Python virtual environment. Other environment variables (e.g. non-absolute directory paths) appear to be read correctly. I'm assuming that this is a git issue given the

Next: Eric Sunshine
Message 1 of 4 in “BUG: git bash / python interaction with absolute paths as environment variables in Windows”
  1. Leland WeathersDec 7, 2021
  2. Eric SunshineDec 7, 2021
  3. Leland WeathersDec 7, 2021
  4. Johannes SchindelinDec 7, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.