Reproduction
Create a repository (default main), FetchFromRemote an upstream whose default is master, then git clone:
warning: remote HEAD refers to nonexistent ref, unable to checkoutThis leaves an empty working tree. The refs are all there; only HEAD dangles.
Expected
The clone checks out the upstream's default branch, or HEAD names one of the branches the fetch brought.
Cause
repository.proto says default_branch is read only when the create makes the repository, and check_prefixes refuses prefixes outside refs/ so a fetch cannot write HEAD. Both are deliberate. But the workaround in fetch-from-a-remote.md ("create the repository with the remote's default branch") requires knowing the remote's default before the fetch. Our application deliberately does not implement the Git protocol; calling FetchFromRemote is how it mirrors, so it has no way to ask the remote for its HEAD before the repository exists.
The fix_head heuristic in the ledger already does the right thing and is skipped when HEAD was named at create.
Possible fixes
Any one of these would be enough:
- ask for the
symrefscapability inls-refs(the request currently sends onlyref-prefix) and recordsymref-targetas HEAD - let a repeat
CreateRepositoryname a newdefault_branch - add a
SetDefaultBranchRPC
Impact
A caller that cannot learn the upstream's default beforehand has to destroy and recreate the repository, and a fresh copy is a full re-transfer.
Environment
Enroute 0.4.1, enroute dev, a repository created through CreateRepository.
Activity
2Most intuitive for me would be that once the fetch finishes, HEAD names one of
the branches the fetch brought. If the upstream's default is master and
master landed here, cloning should check out master, whether or not I knew
what it was called beforehand.
Right now I delete the repository and create it again with the fetched branch,
then fetch again. It works, but it's a full re-transfer, and since I only guess
between main and master, an upstream on develop still ends up with a
dangling HEAD.
A SetDefaultBranch RPC would already let me skip the delete-and-recreate, but
not the guessing: after a fetch I can list what landed, and still can't tell which
of those branches was the upstream's default. ls-refs with symrefs (plus a
ref-prefix HEAD alongside the heads prefix, or some servers won't return it)
gives you symref-target:HEAD in the round trip the fetch already makes, so
FetchFromRemote could record it as the repository's HEAD.
Hey @Foorack, thanks for the bug report! Having a way to change the default branch makes sense to me. That said, I am wondering what would have been the most intuitive outcome for you in this situation?