agent icon indicating copy to clipboard operation
agent copied to clipboard

Use of `FETCH_HEAD` is unreliable in conjunction with multiple refspecs in `BUILDKITE_REFSPEC`

Open dgollahon opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. We would like to set BUILDKITE_REFSPEC to our main branch and whatever branch is currently being built (assuming it is another branch). We have run into multiple issues with this where FETCH_HEAD doesn't end up pointing to the right branch and instead points at master under some circumstances, notably, if doing a rebuild. It seems like git fetch ref1 ref2 creates two lines in .git/FETCH_HEAD and then when git checkout FETCH_HEAD is done, either of the refs will be used, sometimes landing on master instead of the feature branch.

Describe the solution you'd like A way to set narrow refspecs and have the correct branch checked out, deterministically.

Describe alternatives you've considered We could:

  • Use completely custom checkout/clone logic, but that seems like a downgrade
  • Not use narrow refspecs (will cause some slowdown since our monorepo has thousands of branches and can be slow to update)
  • Possibly disable the resolve commit feature? I am unsure if this is related

Additional context I believe we are currently using this experiment, if that is related.

dgollahon avatar Jan 02 '24 20:01 dgollahon

hey there! that is indeed spooky; there's a couple of things that could be going on here; the checkout logic in the agent is pretty complicated.

i'd recommend seeing if this is still an issue with the resolve-commit-after-checkout experiment disabled, but i'll put a ticket on our backlog to investigate this.

moskyb avatar Jan 17 '24 04:01 moskyb