Skip to content

Adjust update to honor custom SSH command#21822

Open
sfc-gh-ksmogor wants to merge 3 commits intoHomebrew:mainfrom
sfc-gh-ksmogor:patch-1
Open

Adjust update to honor custom SSH command#21822
sfc-gh-ksmogor wants to merge 3 commits intoHomebrew:mainfrom
sfc-gh-ksmogor:patch-1

Conversation

@sfc-gh-ksmogor
Copy link
Copy Markdown

@sfc-gh-ksmogor sfc-gh-ksmogor commented Mar 24, 2026

In my use case I use custom ssh command to access homebrew repositories (set as a global config in ~/.gitconfig file). Current brew update doesn't work with my custom repository because of wrong credentials. Tapping still works as expected.
It turned out that setting up explicit GIT_SSH_COMMAND=${GIT_SSH_COMMAND:-ssh} -oBatchMode=yes overrides global git config. Additionally, I couldn't override the default ssh command by exporting GIT_SSH_COMMAND. It happened because the flag wasn't whitelisted.

I propose to fix two things:

  1. Add GIT_SSH_COMMAND to whitelisted list of envs. Currently passing this flag is dead logic without whitelisting.
  2. Check whether the git config have custom ssh command. If so, doesn't override it. Use -oBatchMode only when default ssh implementation is used. Otherwise brew can break custom wrapper by adding ssh-only flag.

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests (excluding integration tests) for your changes? Here's an example. Couldn't find bash scripts tests for update.sh.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes.
    Used for searching the code through and diagnosing the problem with passing the flag to update (comparison between tap and update, suggesting the change when problem was pinned down by local modification).

ENV_VAR_NAMES=(
HOME SHELL PATH TERM TERMINFO TERMINFO_DIRS COLUMNS DISPLAY LOGNAME USER CI SSH_AUTH_SOCK SUDO_ASKPASS
http_proxy https_proxy ftp_proxy no_proxy all_proxy HTTPS_PROXY FTP_PROXY ALL_PROXY
http_proxy https_proxy ftp_proxy no_proxy all_proxy HTTPS_PROXY FTP_PROXY ALL_PROXY GIT_SSH_COMMAND
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to pass this variable through transparently. Can we use USED_BY_HOMEBREW_VARS above instead?

You'll also need to make sure this interacts properly with HOMEBREW_SSH_CONFIG_PATH:

brew/Library/Homebrew/brew.sh

Lines 1093 to 1097 in c437bf7

# Use this configuration file instead of ~/.ssh/config when fetching git over SSH.
if [[ -n "${HOMEBREW_SSH_CONFIG_PATH}" ]]
then
export GIT_SSH_COMMAND="ssh -F${HOMEBREW_SSH_CONFIG_PATH}"
fi

Copy link
Copy Markdown
Author

@sfc-gh-ksmogor sfc-gh-ksmogor Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the USED_BY_HOMEBREW_VARS and it looks fine to use this mechanism.

I also would like to understand how to treat the config and additional flags. Because from my understanding of the current code, it looks like -oBatchMode=yes and -F/config/path options are treated independently (as decorators). So it looks like the custom ssh command should be ready for decorating by those two options. Is it fine to assume that for brew users? Anyone wanted to use custom ssh command has to expect that brew will add some flags to it before passing it to git.

I can change all places that use plain ssh to fill GIT_SSH_COMMAND. Those places will use value from HOMEBREW_GIT_SSH_COMMAND or from global git config.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the USED_BY_HOMEBREW_VARS and it looks fine to use this mechanism.

To be more explicit: we're telling you we don't want to do that.

I can change all places that use plain ssh to fill GIT_SSH_COMMAND.

This seems overkill. Let's keep this change as tightly scoped as possible.

export GIT_TERMINAL_PROMPT="0"
export GIT_SSH_COMMAND="${GIT_SSH_COMMAND:-ssh} -oBatchMode=yes"
# Set GIT_SSH_COMMAND only when user haven't set custom SSH command
if [[ -z "${GIT_SSH_COMMAND}" ]] && ! git config --get core.sshCommand &>/dev/null
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is worth checking if this command is actually a non-empty string and valid?

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.

3 participants