Skip to content

Git Status and Branch APIs Don't Use Current Environment Variables - Missing os.environ.copy() #1416

@nsingl00

Description

@nsingl00

Description

The status() and branch() methods in git.py use static environment inheritance instead of capturing current environment state, causing them to miss runtime environment variable changes that could be critical for Git operations.

Reproduce

In /jupyterlab_git/git.py, the status and branch APIs execute git commands without explicitly passing environment variables:

Status API (git.py:494):
code, status, my_error = await self.__execute(cmd, cwd=path)
Branch APIs (git.py:842, git.py:908):
### In branch_heads() and branch_remotes()
code, heads, error = await self.__execute(cmd, cwd=path)
When these calls reach call_subprocess() (git.py:151):
process = subprocess.Popen(
   cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, env=env
)

Since env=None, the subprocess inherits the static environment from server startup time, not the current os.environ state.

Current Broken Behavior:

JupyterLab server starts

Later during runtime:

os.environ['GIT_CONFIG'] = '/custom/.gitconfig'
os.environ['GIT_SSH_COMMAND'] = 'ssh -i /custom/key'
os.environ['GIT_TRACE'] = '1'  # For debugging

These environment changes are IGNORED by:

git_instance.status()   # Still uses startup environment
git_instance.branch()   # Still uses startup environment

Expected behavior

Both status and branch APIs should start with a clean environment like other APIs

env = os.environ.copy()
code, status, my_error = await self.__execute(cmd, cwd=path, env=env)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions