diff --git a/README.md b/README.md index 843e521..6617bdd 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ ## 🆕 Recent Updates -### v2.1.0 - v2.1.9 - Usage widgets, links, new git insertions / deletions widgets, and reliability fixes +### v2.1.0 - v2.1.10 - Usage widgets, links, new git insertions / deletions widgets, and reliability fixes - **🧩 New Usage widgets (v2.1.0)** - Added **Session Usage**, **Weekly Usage**, **Block Reset Timer**, and **Context Bar** widgets. - **📊 More accurate counts (v2.1.0)** - Usage/context widgets now use new statusline JSON metrics when available for more accurate token and context counts. @@ -58,6 +58,7 @@ - **⏳ Weekly reset timer split (v2.1.7)** - Added a separate `Weekly Reset Timer` widget. - **⚙️ Custom config file flag (v2.1.8)** - Added `--config ` support so ccstatusline can load/save settings from a custom file location. - **🔣 Unicode separator hex input upgrade (v2.1.9)** - Powerline separator hex input now supports 4-6 digits (full Unicode code points up to `U+10FFFF`). +- **🌳 Bare repo worktree detection fix (v2.1.10)** - `Git Worktree` now correctly detects linked worktrees created from bare repositories. ### v2.0.26 - v2.0.29 - Performance, git internals, and workflow improvements diff --git a/package.json b/package.json index cee3408..b1d6508 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ccstatusline", - "version": "2.1.9", + "version": "2.1.10", "description": "A customizable status line formatter for Claude Code CLI", "module": "src/ccstatusline.ts", "type": "module", diff --git a/src/widgets/GitWorktree.ts b/src/widgets/GitWorktree.ts index 795a529..fb39382 100644 --- a/src/widgets/GitWorktree.ts +++ b/src/widgets/GitWorktree.ts @@ -52,25 +52,30 @@ export class GitWorktreeWidget implements Widget { private getGitWorktree(context: RenderContext): string | null { const worktreeDir = runGit('rev-parse --git-dir', context); - if (!worktreeDir) { + if (!worktreeDir) return null; - } const normalizedGitDir = worktreeDir.replace(/\\/g, '/'); - // /some/path/.git or .git + // /some/path/.git or .git (main worktree of regular repo) if (normalizedGitDir.endsWith('/.git') || normalizedGitDir === '.git') return 'main'; // /some/path/.git/worktrees/some-worktree or /some/path/.git/worktrees/some-dir/some-worktree - const marker = '.git/worktrees/'; - const markerIndex = normalizedGitDir.lastIndexOf(marker); - if (markerIndex === -1) { - return null; + const repoMarker = '.git/worktrees/'; + const repoMarkerIndex = normalizedGitDir.lastIndexOf(repoMarker); + if (repoMarkerIndex !== -1) { + const worktree = normalizedGitDir.slice(repoMarkerIndex + repoMarker.length); + return worktree.length > 0 ? worktree : null; } - const worktree = normalizedGitDir.slice(markerIndex + marker.length); + // /some/path/worktrees/some-worktree or /some/path/worktrees/some-dir/some-worktree + const bareMarker = '/worktrees/'; + const bareMarkerIndex = normalizedGitDir.lastIndexOf(bareMarker); + if (bareMarkerIndex === -1) + return null; + const worktree = normalizedGitDir.slice(bareMarkerIndex + bareMarker.length); return worktree.length > 0 ? worktree : null; } diff --git a/src/widgets/__tests__/GitWorktree.test.ts b/src/widgets/__tests__/GitWorktree.test.ts index 30b5734..25a9c00 100644 --- a/src/widgets/__tests__/GitWorktree.test.ts +++ b/src/widgets/__tests__/GitWorktree.test.ts @@ -118,4 +118,25 @@ describe('GitWorktreeWidget', () => { expect(render()).toBe('𖠰 no git'); }); + + it('should render with bare repo worktree', () => { + mockExecSync.mockReturnValueOnce('true\n'); + mockExecSync.mockReturnValueOnce('/some/path/worktrees/some-worktree'); + + expect(render()).toBe('𖠰 some-worktree'); + }); + + it('should render with nested bare repo worktree', () => { + mockExecSync.mockReturnValueOnce('true\n'); + mockExecSync.mockReturnValueOnce('/some/path/worktrees/some-dir/some-worktree'); + + expect(render()).toBe('𖠰 some-dir/some-worktree'); + }); + + it('should handle windows bare repo git-dir paths', () => { + mockExecSync.mockReturnValueOnce('true\n'); + mockExecSync.mockReturnValueOnce('C:\\repo\\worktrees\\some-worktree'); + + expect(render()).toBe('𖠰 some-worktree'); + }); }); \ No newline at end of file