Include gitConfigAuthArgs on git checkout when filter is set#3707
Merged
doriable merged 5 commits intoMar 24, 2025
Conversation
When using `filter` `buf` will fail to run `git checkout` as the credentials aren't passed to `git`. This results in failures such as: ``` Failure: could not clone https://github.com/foo/bar.git: exit status 128 fatal: could not read Username for 'https://github.com': No such device or address fatal: could not fetch <SHA> from promisor remote ``` I noticed this while testing bufbuild/buf-action#142 which relies on overriding `credential.helper` for authentication in GitHub Actions.
doriable
reviewed
Mar 24, 2025
Comment on lines
+197
to
+202
| // Include auth when using git-filters, so git can pull the required | ||
| // objects from the origin. | ||
| checkoutArgs := []string{"checkout", "--force", "FETCH_HEAD"} | ||
| if options.Filter != "" { | ||
| checkoutArgs = append(gitConfigAuthArgs, checkoutArgs...) | ||
| } |
Member
There was a problem hiding this comment.
This approach seems overall reasonable -- we could address this alongside the sparse-checkout, for example:
if options.Filter != "" {
checkoutArgs = append(gitConfigAuthArgs, checkoutArgs...)
if options.SubDir != "" {
// The sparse checkout of the subdir...
}
}
Member
There was a problem hiding this comment.
Apologies, I should've commented this earlier -- going through it, it actually makes sense to prepend gitConfigAuthArgs to all invocations (since this is how we are fetching). So instead of checking this against options.Filter != "", it should be prepended to all the checkout and sparse-checkout calls (similar to how we're prepending to the submodules call).
doriable
approved these changes
Mar 24, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When using
filterbufwill fail to rungit checkoutas the credentials aren't passed togit.This results in failures such as:
I noticed this while testing bufbuild/buf-action#142 which relies on overriding
credential.helperfor authentication in GitHub Actions.