sl goto detaches git HEAD in .git mode, preventing bookmark auto-advance on commit
When using Sapling in .git mode (existing git repo, no .sl directory), running sl goto
Expected behavior: sl goto
Actual behavior: git HEAD is detached after sl goto. Commits create new changesets but the bookmark pointer does not move,
requiring a manual sl bookmark -r .
Steps to reproduce:
In an existing git repo (.git mode, no .sl directory)
sl bookmark feature sl goto feature echo "test" > foo.txt sl addremove && sl commit -m "test commit" sl bookmarks # feature still points to the pre-commit hash git branch # HEAD is detached
Workaround: Follow sl goto
Environment:
- Sapling version: 0.2.20260317-201835
- Mode: .git (no .sl directory)
- OS: macOS 14
Hey! 👋 I ran into this exact issue today while trying to use Sapling over an existing Git monorepo at work — the detached HEAD after sl goto is a real footgun, especially when you only discover the problem after making several commits and noticing your bookmark hasn't moved.
I dug into this a bit and want to share what I found, since I think it might help narrow down where the fix should go.
The core issue seems to be that in .git mode, sl goto <bookmark> resolves the target to a commit hash and passes that hash to the underlying Git checkout operation — rather than passing the branch/ref name that the bookmark maps to. Git, of course, detaches HEAD whenever you checkout <hash> directly.
The fix conceptually needs to happen in the .git mode bridge: before performing the checkout, Sapling should check whether the target commit is the tip of a known Git branch, and if so, perform git checkout <branch-name> instead of git checkout <hash>. This mirrors exactly what git checkout <branchname> does natively.
A few questions for the maintainers before I go further:
- Is the relevant code path in
eden/scm/sapling/hg.pyaround theupdate/gotocommand, or is the.gitbridge handled somewhere ineden/scm/lib? - Is there a preferred way to run the existing test suite for
.gitmode locally to validate a fix? - Is there a known mapping between Sapling bookmarks and Git branch refs stored somewhere at runtime, or would we need to do a live ref lookup?
Happy to put together a PR once I understand the right place to make the change. This is a high-impact fix for anyone trying Sapling as a drop-in Git client.