Skip to content

fix(jj): show closest bookmark instead of 'detached' in UI#144

Merged
agavra merged 1 commit intoagavra:mainfrom
martintrojer:jj-closest-bookmark
Jan 24, 2026
Merged

fix(jj): show closest bookmark instead of 'detached' in UI#144
agavra merged 1 commit intoagavra:mainfrom
martintrojer:jj-closest-bookmark

Conversation

@martintrojer
Copy link
Copy Markdown
Collaborator

Problem:
When running tuicr in jj-mode, the header always showed [jj:detached] even when working on commits that descend from bookmarked commits. This is because the code only checked for bookmarks directly on @.

Solution:
Use a two-step bookmark discovery approach:

  1. First check if @ has a bookmark directly
  2. Fall back to 'heads(::@ & bookmarks())' to find the closest ancestor bookmark (the one you're most likely working towards)
  3. Extract the first local bookmark name, filtering out remote tracking refs like 'main@upstream'

Test coverage:

  • test_jj_bookmark_on_current_revision: bookmark directly on @
  • test_jj_bookmark_on_ancestor_revision: bookmark on ancestor (common case)
  • test_jj_no_bookmarks: graceful fallback when no bookmarks exist

Problem:
When running tuicr in jj-mode, the header always showed [jj:detached]
even when working on commits that descend from bookmarked commits.
This is because the code only checked for bookmarks directly on @.

Solution:
Use a two-step bookmark discovery approach:
1. First check if @ has a bookmark directly
2. Fall back to 'heads(::@ & bookmarks())' to find the closest
   ancestor bookmark (the one you're most likely working towards)
3. Extract the first local bookmark name, filtering out remote
   tracking refs like 'main@upstream'

Test coverage:
- test_jj_bookmark_on_current_revision: bookmark directly on @
- test_jj_bookmark_on_ancestor_revision: bookmark on ancestor (common case)
- test_jj_no_bookmarks: graceful fallback when no bookmarks exist
@martintrojer
Copy link
Copy Markdown
Collaborator Author

A clarification regarding range selects and implications on jj bookmarks.

The git VCS integration uses the current checkout (HEAD) for working tree diffs and does not attempt to find a branch for arbitrary commit ranges—it simply shows "detached" if not on a branch. This matches the default behavior in most git UIs.

Therefore, for jj, showing the closest bookmark to the selected revision or commit range, is consistent.

Copy link
Copy Markdown
Owner

@agavra agavra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@agavra agavra merged commit f3255cb into agavra:main Jan 24, 2026
4 checks passed
@martintrojer martintrojer deleted the jj-closest-bookmark branch January 25, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants