You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Workspace checkout reports an existing default branch as missing on repositories with many branches #9195
The workspace checkout script reports the workspace default branch as missing when the repository has a large number of branches, even though the branch exists. Implement then fails with:
The workspace default branch "develop" does not exist in https://bitbucket.org/<workspace>/<repo>.git. The repository's default branch is "master". Update it in Workspace settings → Repository.
The message happens for every branch, including the repository's own default branch (master above). Planning shows the same problem as a warning and falls back to the remote default branch.
Cause
WorkspaceCheckoutScript() in pkg/components/runner/workspace_agent_resources.go runs with set -euo pipefail and checks the branch like this:
grep -q exits on the first match. When the ls-remote output is larger than the pipe buffer, printf or awk is still writing and gets SIGPIPE. Under pipefail, the pipeline then reports failure, so a branch that matched is treated as missing.
Reproduction
set -euo pipefail
heads="$(printf '%040d\trefs/heads/develop\n' 0;foriin$(seq 1 5000);doprintf'%040d\trefs/heads/feature/branch-%d-with-a-longish-name\n' 0 $i; done)"printf '%s\n' "$heads" | awk '{print $2}' | grep -Fxq refs/heads/develop && echo found || echo "not found"# prints: not found
I have this fix locally, with a regression test in workspace_checkout_test.go. The test creates a bare repo with 3,000 branches and checks that the requested branch is checked out. I can open a PR.
Environment
Bitbucket repository with several hundred branches
Local development setup (make dev.up, Docker Fleet Manager runner)
Activity