Handle unborn Git branches when staged changes are hidden. - #297
Open
am5083 wants to merge 1 commit into
Open
Conversation
dgutov
reviewed
Sep 10, 2026
| (append | ||
| (vc-switches 'git 'diff) | ||
| (list "-p" "--cached" | ||
| (or diff-hl-reference-revision |
Owner
There was a problem hiding this comment.
Hi! Could you try this version?
(or diff-hl-reference-revision
(vc-git--rev-parse "HEAD")
"4b825dc642cb6eb9a060e54bf8d69288fbee4904")still with diff-index, without switching to git diff. The above literal is the "empty repository" hash for SHA-1, we use it below too.
Owner
There was a problem hiding this comment.
Hmm, or maybe not - that adds +1 process call on the common path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #298
When
diff-hl-show-staged-changesis nil, diff-hl currentlycomputes the staged/reference layer with:
This fails in a repository with an unborn branch because
HEADdoes not exist yet. Synchronous updates signal status 128.
Asynchronous updates subsequently pass Git's fatal diagnostic to
diff-hl-changes-from-buffer, which fails indiff-beginning-of-hunk.Use
git diff --cached [<commit>]instead. When no explicit commitis supplied, Git compares the index against
HEADwhen it existsand against the empty tree on an unborn branch. An explicit
diff-hl-reference-revisionis still passed through unchanged.The regression test creates a temporary unborn repository with
separate staged and worktree changes and verifies both layers with
synchronous and asynchronous updates. The existing test also
checks implicit and explicit
HEADreferences.Tested with Emacs 30.2:
git diff --checkpassed