You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix null pointer panic in listFiles when repository has no commits or invalid HEAD (#202)
Fixes a panic that occurs when calling repo.Head().Hash() in empty git repositories,
git worktrees, or repositories with invalid HEAD references. The issue happened in
pkg/header/check.go where head could be nil, causing a null pointer dereference
when calling head.Hash().
This commonly occurs in the following scenarios:
- Empty git repositories with no initial commits
- Git worktrees with detached HEAD or invalid branch references
- Corrupted repositories with invalid HEAD pointers
- New worktrees created from non-existent commits or branches
Changes:
- Add proper null check for head reference before calling head.Hash()
- Add error handling for repo.Head() to gracefully handle edge cases
- Skip git-based file discovery when repository has no commits or invalid HEAD
- Add test cases for empty repositories and worktree scenarios in check_test.go
- Ensure graceful fallback to glob-based file discovery in problematic git states
Resolves panic at pkg/header/check.go:99 when working with empty git repositories
or git worktree environments with invalid HEAD references.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-authored-by: Claude <[email protected]>
0 commit comments