Using credential helpers for git commands

I have a credential helper installed into /usr/local/bin which works just fine when using command-line git commands. However, when using brew tap or other commands, the helper is not triggered. It appears that the PATH variable is being stripped out by homebrew before actually calling in to the underlying git command.

The only credential helpers that are available during homebrew executions are those that are found in git --exec-path. I can add my credential helper there and it works - but that doesn’t seem like an “appropriate” approach.

Is there some variable or flag or something that I can use to preserve the PATH environment variable when running the underlying git commands?

For a lot of reasons, almost all related to failing builds, the environment is almost completely ignored inside homebrew. Especially PATH can cause a lot of issues. As far as I know there isn’t any way to circumvent this.

You might be able to make a pull request that will expose the original environment to git though.

Yeah - I figured it was some kind of filtering for builds - but my question was if it would be possible to not filter them for git operations.

We used to have an environment variable HOMEBREW_NO_ENV_FILTERING that would disable this behavior, but we’ve since removed that. A pull request to look for git credential helpers during brew update etc would be the way to go for this, but the design would have to be really careful to not mess anything else up or leave Homebrew in an un-updateable state if git credentials are misconfigured.

One other solution that I just thought of… I think you can set HOMEBREW_DEVELOPER (to enable nonstandard gits) and HOMEBREW_GIT_PATH to a git binary that will look in the right place for your credential helpers. But again you would have to be careful to not break updating, and this is an unsupported configuration so you would be responsible for resolving any breakages that occur rather than asking for help on a github issue.

I’d love to put together a pull request! Can someone point me to where in the code the filtering happens (I think the git stuff happens in the shims folder, but I’ve never worked on brew code itself - just formulas). If someone could point me to where to start, I’d appreciate it…and I can work something up.