[git] jj cannot export refs when remote-tracking branch is path-like prefix to a branch
My repo has a remote-tracking branch, e.g. origin/test, and I have a local branch test/something. When trying to export refs to Git, jj complains with
Internal error: Failed to export refs to underlying Git repo: cannot lock ref 'refs/heads/test', there are refs beneath that folder; class=Reference (4)
Note that because Git uses file paths to store refs, it doesn't allow both test and test/something to be branches at the same time.
Hmm, I'm not sure what to do about that other than to skip one of the refs in such cases. That would at least be better than failing.
I think I've heard that the reftable format allows that case but even if that's true, it's a long time until we can start depending on that...
A band-aid might be to add args to jj git export to control which branches get exported. e.g. in this particular instance, I only care about the branch I was working on, so I could make do with exporting just that branch.
This just happened to me when trying to jj git fetch - The GH remote has a foo branch and 3 foo/bar branches (all of which are other people's, so i can't delete/rename them), so I can't fetch any more... 😓
~Is there any "local" workaround for this?~
Following a short Discord discussion with Martin, using git fetch directly and only fetching specific branches "solved" the problem.
I'm almost done with a fix for this. The only thing I'm wondering is how to report it to the user. I've made git export report the names of branches that failed to export, but I'm not sure if we should do the same for the automatic export in colocated workspaces. Since @tp-woven and @chooglen have run into this in practice, do you think it would be too spammy to see a message about it after every command?
FYI, the message I added to git export looks like this:
Failed to export some branches:
main/sub
That indicates that a branch with the empty string as name and the main/sub branch failed. We can of course use a different format for automatic exports (and for explicit git export if you think we should).
Thanks Martin!
I think showing this for every command is OK, as it would encourage me to actually resolve the issue. Another thing that would be useful (for error messages in general, TBH) would be suggestions on how to resolve these situations.
Another thing that would be useful (for error messages in general, TBH) would be suggestions on how to resolve these situations.
Good point. I sent #812 to add a hint.
Thanks!