Repository navigation
Ask git whether leaving a detached HEAD loses commits - #210
Conversation
|
Nice. The cost doesn't bother me too much because the common case is cheap, and it occurs in a relatively narrow set of circumstances. I don't think making thousands of commits with a detached HEAD is a common enough use case to worry about performance here. I appreciate the profiling as always, the results are interesting.
Sure, since we get that info "for free" now, why not present it to the user.
No problem changing translatable text if that's an improvement in the UI - don't worry. One of the last things I do before each release is to update the .po files for Weblate and take care of French (that makes me proofread the English text with fresh eyes, and sometimes it reveals strings with poor wording). |
|
Done: the warning now counts the lost commits, with your wording, and SwitchBranch says "If you switch to {branch}". The n-1 goes through _n ("1 more commit", "2 more commits"). Counting costs the same as the yes/no check, since git walks the same commits either way (median ms):
The "You are in Detached HEAD mode" paragraph is gone, since the sentence now names the detached HEAD. Tags, remote branches and the stash also keep a commit reachable, but git's own message says "any of your branches" too, so I kept "any other branch". |
|
Applied in fca8b93. Both hashes use tquo (no HTML to escape). The test keeps the exact "1 more commit" / "N more commits" rather than |
SwitchBranch and CheckoutCommit warned about losing a detached HEAD based on the graph: whether another ref sat at HEAD or a commit above it. When HEAD was beyond the loaded commits, the graph couldn't tell, so GF always warned, even if a branch still reached HEAD. It also warned when only refs/stash or a ref outside refs/heads, refs/remotes and refs/tags kept the commit. RepoTask.flowCommitsLeftBehind asks git the question its own checkout warning answers: `git rev-list -n1 HEAD ^target --single-worktree --exclude=HEAD --not --all`, so this worktree's refs count, but not HEAD or other worktrees' HEADs. It runs in the background like other git calls. Graph.getCommitFrame lost its last caller and is gone.
The warning said "You might lose track of this commit" back when GF only guessed. git now gives the exact count, so the warning names the detached HEAD and how many more commits no other branch reaches. commitsLeftBehind() moves to committasks.py, next to readCommentString(), and counts with `rev-list --count` instead of stopping at the first commit, at the same cost.
Quoted hashes read more easily in the sentence. The Check Out dialog also gets "Check Out X" / "Don't Check Out" buttons like the Switch dialog's.
Since jorio#211, tasks pass commits to git as <hash>^{commit}. rev-list read the bare hash correctly already, but this keeps one rule for every task.
|
Can you please look at the conflicts? Then I'll merge. Thanks! |
fca8b93 to
b176995
Compare
Follow-up to #205. SwitchBranch and CheckoutCommit decided from the graph whether leaving a detached HEAD would lose commits. Beyond the loaded commits the graph couldn't tell, so GF always warned, even when a branch still reached HEAD. It also warned when only refs/stash or a ref outside refs/heads, refs/remotes and refs/tags kept the commit.
RepoTask.flowCommitsLeftBehindnow asks git the question thatgit checkout's own warning answers:git rev-list -n1 HEAD ^<target> --single-worktree --exclude=HEAD --not --all. I compared it with that warning for stashes, tags, remote and custom refs, refs/bisect, and other worktrees' HEADs and per-worktree refs; they agree.It runs only when HEAD is detached, as a background git process. One switch on jellyfin-web (30,000 commits, 10,000 loaded):
Question: the dialog says "You might lose track of this commit". Now that the answer is exact, should it say how many commits are left behind, like git does? That changes a translated string, so I left it.
Tested: full suite on PyQt6, PySide6 and PyQt5 (testToggleWordWrap fails on master too, see #208); branch and commit tests on Windows 11.
Prepared with Claude Code; I reviewed the changes.
Checklist