sapling icon indicating copy to clipboard operation
sapling copied to clipboard

sl goto detaches git HEAD in .git mode, preventing bookmark auto-advance on commit

Open dhruvrajan opened this issue 6 months ago • 1 comments

When using Sapling in .git mode (existing git repo, no .sl directory), running sl goto checks out the commit hash rather than the branch name, leaving git HEAD in a detached state.

Expected behavior: sl goto should attach HEAD to the corresponding git branch (equivalent to git checkout ), so that subsequent commits auto-advance the bookmark.

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 . to update it.

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 with git checkout to reattach HEAD. Once attached, commits advance the bookmark correctly.

Environment:

  • Sapling version: 0.2.20260317-201835
  • Mode: .git (no .sl directory)
  • OS: macOS 14

dhruvrajan avatar May 14 '26 17:05 dhruvrajan

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:

  1. Is the relevant code path in eden/scm/sapling/hg.py around the update/goto command, or is the .git bridge handled somewhere in eden/scm/lib?
  2. Is there a preferred way to run the existing test suite for .git mode locally to validate a fix?
  3. 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.

AkshatRaj00 avatar May 23 '26 18:05 AkshatRaj00