Git Fetch Flags

Hi,

We use a monorepo that needs to compare the latest origin for the main branch, however Buildkite only grabs the origin for the branch that triggered the build. If the machine is fresh this is fine because the clone will have fetched the latest for main, but with on demand machines they have stale main branches.

I’ve tried using the git-fetch-flags Buildkite Agent configuration v3 | Buildkite Documentation however adding --all doesn’t work as it conflicts with the explicit fetch of only one branch.

Is there something I am missing that would make this work? Or since this flag is experimental, could something be added that says if --all is added to the flags then don’t try and fetch only the current branch?

Cheers,
James

Hey @jamsjordn!

Thanks for the message- hope you are well :slightly_smiling_face:

Just wanted to confirm if you are setting the -all flag as part of an agent configuration? The BUILDKITE_GIT_FETCH_FLAGS as you’ve most likely seen in the docs is agent level configuration, so loading it with a Agent level hook/config export would suffice (by default the flags are -v --prune

If you wanted to fetch everything from upstream, a git fetch -v --prune origin should do the trick.

Hope that helps!

Hi,

I was using a pre-checkout hook to update BUILDKITE_GIT_FETCH_FLAGS
I was using it through a community plugin but everything seems correct there GitHub - Hivebrite/git-flags-buildkite-plugin: Plugin to set BUILDKITE_GIT_CLONE_FLAGS & BUILDKITE_GIT_FETCH_FLAGS

I’ve just tried using -v --prune origin but when the actual git fetch is performed -- origin be41afea5b706817ffb1b828deea74fffcd34dc9 gets added to it resulting in

From what I can tell in agent/git.go at main · buildkite/agent · GitHub on line 118, the git fetch always appends the -- origin hash part of the command and so through this I don’t think it’d currently be possible to fetch both the current branch and master through these means.

@jamsjordn

We believe the reason you are seeing -- origin be41afea5b706817ffb1b828deea74fffcd34dc9 gets added is because your build is for a commit push event. Is that correct ? Please can you send your build url to support@buildkite.com as that would help us check this further.

Hi,

This is a build for a commit push, I’ve sent through the build URL to that email.

Also we are using Bitbucket if that helps, I can see there is some GitHub specific code that would not be applied to us.