Skip to content

feat: implement heroku git:credentials as a git credential helper#3683

Merged
erika-wallace merged 3 commits intofeat/credential-mgr-integrationfrom
ew/git-cred-helper
Apr 29, 2026
Merged

feat: implement heroku git:credentials as a git credential helper#3683
erika-wallace merged 3 commits intofeat/credential-mgr-integrationfrom
ew/git-cred-helper

Conversation

@erika-wallace
Copy link
Copy Markdown
Contributor

@erika-wallace erika-wallace commented Apr 27, 2026

Summary

This PR implements heroku git:credentials as a git credential helper for Heroku Git authentication.

When git needs credentials for git.heroku.com, it will call heroku git:credentials get, which reads the stored Heroku auth token and outputs it in the format git expects.

Changes:

  • src/commands/git/credentials.ts
    • Implements the git-credential protocol (get, store, erase operations)
    • Reads key=value pairs from stdin — terminated by a blank line
    • Validates protocol=https and host=git.heroku.com before outputting credentials
  • src/lib/git/git.ts
    • Added configureCredentialHelper(), which writes !heroku git:credentials as a URL-scoped global git credential helper. Since the helper starts with !, Git executes it as a shell command.
    • Wrapped ux.error() with try/catch in spawn's error handler to route errors through the Promise rejection channel
  • src/commands/auth/login.ts
    • Calls configureCredentialHelper() after successful login; silently ignores errors
  • src/commands/apps/create.ts, src/commands/git/clone.ts, src/commands/git/remote.ts
    • Each command calls configureCredentialHelper() after git operations to handle the case where git was not installed when heroku login was run

Tests:

  • Added tests for git:credentials covering protocol operations and host validation
  • Added git credential helper tests to apps:create, git:remote, and git:clone
  • Created new test file for auth:login covering login validation and git credential helper configuration
  • Updated credentialManagerStub to allow custom return values per test
  • Fixed previously skipped tests in test/unit/lib/git/git.unit.test.ts; made execFilePromise accessible as an instance property to properly stub cp.execFile after promisify

Note on git unit tests: The git commands are not well tested, tracked in W-13589124. This PR fixes the skipped tests and adds coverage for the new functionality. Remaining improvements are tracked in that work item.

Type of Change

Breaking Changes (major semver update)

  • Add a ! after your change type to denote a change that breaks current behavior

Feature Additions (minor semver update)

  • feat: Introduces a new feature to the codebase

Patch Updates (patch semver update)

  • fix: Bug fix
  • deps: Dependency upgrade
  • revert: Revert a previous commit
  • chore: Change that does not affect production code
  • refactor: Refactoring existing code without changing behavior
  • test: Add/update/remove tests

Testing

Notes:

You need access to a Heroku app with a git remote for testing git push heroku main. The test steps will temporarily replace your installed Heroku CLI with the local build and modify your global git config — both are restored in the cleanup steps.

Steps:

  1. Pull down this branch
  2. heroku logout
  3. npm install && npm run build
  4. npm link — replaces the installed version of Heroku with this local build
  5. restart the terminal
  6. which heroku — confirm it shows a local/npm path rather than homebrew
  7. heroku login
  8. git config --global credential.https://git.heroku.com.helper — should return !heroku git:credentials
  9. Edit ~/.netrc and remove any lines for git.heroku.com — this forces git to use the credential helper instead of netrc directly
  10. cd into a local app directory with a Heroku remote
  11. GIT_TRACE=1 git push heroku main — in the trace output, confirm you see run_command: 'heroku git:credentials get' near the start of authentication
  12. Confirm the push completes successfully or "Already up to date"

Cleanup:
13. heroku logout
14. npm unlink -g heroku
15. which heroku — confirm the original Heroku path is restored
16. git config --unset --global credential.https://git.heroku.com.helper
17. heroku login— re-authenticates and writes fresh credentials to ~/.netrc

Screenshots (if applicable)

Related Issues

GUS work item: W-22182925

@erika-wallace erika-wallace requested a review from a team as a code owner April 27, 2026 18:56
@erika-wallace erika-wallace changed the title feat: add git credential helper for git authorization feat: implement heroku git:credentials as a git credential helper Apr 27, 2026
Copy link
Copy Markdown
Contributor

@tlowrimore-heroku tlowrimore-heroku left a comment

Choose a reason for hiding this comment

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

LGTM!

@erika-wallace erika-wallace merged commit 781e99e into feat/credential-mgr-integration Apr 29, 2026
33 of 34 checks passed
@erika-wallace erika-wallace deleted the ew/git-cred-helper branch April 29, 2026 16:56
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.

2 participants