Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflows/remote-bazel: fix default branch not found #6283

Merged
merged 3 commits into from
Apr 5, 2024

Conversation

sluongng
Copy link
Contributor

@sluongng sluongng commented Apr 1, 2024

Listing all local branches to find the default branch could yield unreliable results.
For example, in Github Action, there is no local refs/heads/{master,main} written by the actions/checkout plugin.
It's also interesting how refs/remote/origin/HEAD symbolic ref is not written, so trying to use the symbolic ref might not work.
refs/remote/origin/master is written conditionally based on whether fetch-depth: 0 is configured in the actions/checkout plugin or not.

Employ 2 strategies to detect the default branch: local and remote.
For local strategy, we attempt to read refs/heads/{master,main}, each, from 2 places: in the .git/refs directory and the .git/packed-refs file.
For remote strategy, run git ls-remote origin and see if either refs/heads/{master,main} exists.

@sluongng sluongng force-pushed the sluongng/fix-remote-bazel-workflow branch 2 times, most recently from d95fb63 to f749f62 Compare April 1, 2024 13:33
cli/remotebazel/remotebazel.go Show resolved Hide resolved
cli/remotebazel/remotebazel.go Outdated Show resolved Hide resolved
@sluongng sluongng force-pushed the sluongng/fix-remote-bazel-workflow branch from f749f62 to dc6c336 Compare April 3, 2024 14:56
cli/remotebazel/remotebazel.go Show resolved Hide resolved
cli/remotebazel/remotebazel.go Outdated Show resolved Hide resolved
cli/remotebazel/remotebazel.go Show resolved Hide resolved
@sluongng sluongng force-pushed the sluongng/fix-remote-bazel-workflow branch 7 times, most recently from bca6e56 to d2346b1 Compare April 5, 2024 14:46
@sluongng sluongng force-pushed the sluongng/fix-remote-bazel-workflow branch from 8a5eb7c to bf1238c Compare April 5, 2024 15:14
cli/remotebazel/remotebazel.go Outdated Show resolved Hide resolved
cli/remotebazel/remotebazel.go Outdated Show resolved Hide resolved
@sluongng sluongng merged commit e52435b into master Apr 5, 2024
17 of 19 checks passed
@sluongng sluongng deleted the sluongng/fix-remote-bazel-workflow branch April 5, 2024 16:08
maggie-lou added a commit that referenced this pull request Apr 12, 2024
maggie-lou added a commit that referenced this pull request Apr 12, 2024
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.

None yet

3 participants