Skip to content

Report no head for a worktree on an unborn branch [patch] - #212

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/165-unborn-worktree-head
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/165-unborn-worktree-head

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #165

What changed

git worktree list --porcelain still prints a HEAD line on an unborn branch, and its value is the all-zero null id. GitWorktreeParser turned that into a GitCommitSha, so GitWorktree.Head looked like a real commit.

  • IsNullObjectId has moved from GitSubmoduleParser (private) to GitParseValues (internal). Its body is unchanged, and the submodule parser now calls the shared copy.
  • GitWorktreeParser now reports an all-zero HEAD as Head = null. Because the check looks at the digits rather than a fixed length, both 40- and 64-character ids are covered.
  • The GitWorktree.Head remarks now say that an unborn branch also reports null.

Tests

  • Parser: ReportsNoHeadForAnUnbornBranch covers the SHA-1 (40) and SHA-256 (64) forms.
  • Integration: WorktreesReportsNoHeadForAFreshRepositoryAsync calls Worktrees() on a freshly initialised repository and expects Head == null with branch main.
  • To show the tests depend on the fix, I changed the check to IsNullObjectId(value + "x"), which never matches. All three cases failed, then passed again once the change was restored.
  • Full suite on Linux with git 2.43 and KTSU_GIT_INTEGRATION_TESTS_REQUIRED=1: 803 of 803 passed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BkmjSwCY4KW87X2ccQhj7T


Generated by Claude Code

git worktree list prints a HEAD line even on an unborn branch, carrying
the all-zero null id, and the parser passed it through as a commit. The
null-id check GitSubmoduleParser already used moves to GitParseValues so
the worktree parser can share it, and an all-zero HEAD (40 or 64
characters) now yields Head = null, as GitWorktree.Head documents.

Fixes #165

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BkmjSwCY4KW87X2ccQhj7T
@sonarqubecloud

Copy link
Copy Markdown

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.

Worktrees() reports a worktree on an unborn branch as sitting at commit 0000000… instead of Head = null

2 participants