Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions cmd/bt/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func runStatus(cmd *cobra.Command, args []string) error {

// Print worktrees
fmt.Println("Worktrees:")
fmt.Printf(" %-20s %-30s %s\n", "BRANCH", "PATH", "STATUS")
var unmanagedWorktrees []string

// Determine which worktree we're currently in
Expand All @@ -97,6 +96,25 @@ func runStatus(cmd *cobra.Command, args []string) error {
}
}

// Calculate dynamic column widths
maxBranchLen := len("BRANCH")
maxPathLen := len("PATH")
for _, wt := range worktrees {
branchName := wt.Branch
if branchName == "" {
branchName = "(detached)"
}
if len(branchName) > maxBranchLen {
maxBranchLen = len(branchName)
}
relPath, _ := filepath.Rel(repoRoot, wt.Path)

Copilot AI Mar 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filepath.Rel errors are ignored when computing/printing relPath. On Windows (different volumes) or other edge cases, Rel can fail and relPath will be empty, which also skews maxPathLen and produces misleading output. Handle the error and fall back to wt.Path (or another sensible default) when Rel returns an error.

Suggested change
relPath, _ := filepath.Rel(repoRoot, wt.Path)
relPath, err := filepath.Rel(repoRoot, wt.Path)
if err != nil {
// If we cannot compute a relative path (e.g., different volumes on Windows),
// fall back to the original worktree path to avoid empty/misleading output.
relPath = wt.Path
}

Copilot uses AI. Check for mistakes.
if len(relPath) > maxPathLen {
maxPathLen = len(relPath)
}
Comment on lines +99 to +113

Copilot AI Mar 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Column widths are calculated with len(), but fmt’s %-*s padding uses rune count. If branch names or paths contain non-ASCII characters, the computed widths can be too large/small and columns will misalign. Consider using utf8.RuneCountInString (or a display-width helper) when computing maxBranchLen/maxPathLen.

Copilot uses AI. Check for mistakes.
}

fmt.Printf(" %-*s %-*s %s\n", maxBranchLen, "BRANCH", maxPathLen, "PATH", "STATUS")

for _, wt := range worktrees {
prefix := " "
// Check if current directory is within this worktree
Expand All @@ -113,10 +131,10 @@ func runStatus(cmd *cobra.Command, args []string) error {
// Check if this worktree is broken (path doesn't exist)
if _, isBroken := brokenBranches[branchName]; isBroken {
relPath, _ := filepath.Rel(repoRoot, wt.Path)
fmt.Printf(" %s %-20s %-30s %s%s\n",
fmt.Printf(" %s %-*s %-*s %s%s\n",
prefix,
branchName,
relPath,
maxBranchLen, branchName,
maxPathLen, relPath,
"[Broken]",
" ⚠️",
)
Expand All @@ -136,10 +154,10 @@ func runStatus(cmd *cobra.Command, args []string) error {

relPath, _ := filepath.Rel(repoRoot, wt.Path)

fmt.Printf(" %s %-20s %-30s %s%s\n",
fmt.Printf(" %s %-*s %-*s %s%s\n",
prefix,
branchName,
relPath,
maxBranchLen, branchName,
maxPathLen, relPath,
status,
statusSymbol,
)
Expand Down
Loading