Skip to content

Support env in the simpleGit builder options - #1203

Closed
Amatewasu wants to merge 1 commit into
steveukx:mainfrom
Amatewasu:fix/support-env-in-constructor-options-1189
Closed

Amatewasu wants to merge 1 commit into
steveukx:mainfrom
Amatewasu:fix/support-env-in-constructor-options-1189

Conversation

@Amatewasu

@Amatewasu Amatewasu commented Oct 7, 2026 •

Copy link
Copy Markdown

Fixes #1189

Note

LLM-generated contribution: this pull request (code, tests, changeset and description) has been generated by a LLM.

Problem

As reported in #1189, supplying GIT_SSH_COMMAND (or any other variable) through the env property of the simpleGit() builder options worked in v3 but is silently ignored in v4 - the Git constructor only reads baseDir, maxConcurrentProcesses and trimmed, and env is not part of the published SimpleGitOptions typings. Users migrating from v3 get no error and no typings hint that the constructor approach stopped working.

Change

  • env supplied to the simpleGit() builder is now used as the initial executor environment, using the same interface as calling .env({...}) on the created instance (single-key .env(name, value) calls merge into it, an object argument replaces it entirely).
  • env is added to the SimpleGitOptions typings.
  • The v4 environment guard applies identically to both approaches: guarded keys (every GIT_-prefixed key plus known-vulnerable keys such as EDITOR / PAGER) supplied through the constructor reject the tasks they are used with unless named in allowEnvironment, matching the existing .env() behaviour described in the v4 release notes.
simpleGit({
   unsafe: { allowUnsafeSshCommand: true },
   allowEnvironment: ['GIT_SSH_COMMAND'],
   env: { ...process.env, GIT_SSH_COMMAND },
});

Tests

  • Unit tests (mocked child process) covering: constructor env reaching the spawned process, guarded-key rejection without allowEnvironment, the GIT_SSH_COMMAND scenario from Bug: git.env('GIT_SSH_COMMAND', ...) is ignored, while constructor env works #1189, and the merge/replace interaction between constructor env and .env().
  • Integration tests against a real git process proving an allow-listed constructor env variable is honoured (commit author) and that unlisted guarded keys reject the task.
  • Changeset included.

The env property supplied to the simpleGit() builder was silently ignored,
so the workaround from steveukx#1189 of passing GIT_SSH_COMMAND through the
constructor stopped working without any error or typings to flag it.

The constructor env is now used as the initial executor environment, using
the same interface as calling .env({...}) on the instance - guarded keys
supplied this way reject the tasks they are used with unless named in
allowEnvironment, matching the .env() behaviour.
@changeset-bot

changeset-bot Bot commented Oct 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0d6b054

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
simple-git Patch
@simple-git/test-javascript-cjs-consumer Patch
@simple-git/test-javascript-esm-consumer Patch
@simple-git/test-typescript-cjs-consumer Patch
@simple-git/test-typescript-esm-consumer Patch
@simple-git/test-typescript-strict-cjs-consumer Patch
@simple-git/test-typescript-strict-esm-consumer Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@steveukx

steveukx commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Thank you for creating the pull request.

I've added a note to the issue to explain why the code sample wasn't working - the change relates to how the .env method is being called, which means this change isn't required.

@steveukx steveukx closed this Oct 7, 2026
@Amatewasu

Copy link
Copy Markdown
Author

Yes thank you a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: git.env('GIT_SSH_COMMAND', ...) is ignored, while constructor env works

3 participants