Skip to content

Conversation

@bigs
Copy link
Contributor

@bigs bigs commented Oct 21, 2025

The --quiet / -q switch for the list subcommand provides scripting friendly output to the list subcommand, outputting only the values from the "PATH" column of the pre-existing output.

Motivation

I took some inspiration from the docker ps subcommand, which has a convenient and scripting-friendly -q switch stripping all non-essential information. My primary motivation for this was to make my own take on the shell scripting you provided that uses fzf to fuzzy search the branches of the worktree. My current script is a little ugly, because I parse away irrelevant output:

wcd() {
  local dir selected

  if [[ $# -eq 0 ]]; then
    selected=$(wtp list | tail -n +3 | awk '{print $1}' | sed 's/\*$//' | fzf --prompt="Select branch: ")
    echo "Selected: $selected"
    [[ -z "$selected" ]] && return 1
  else
    selected="$1"
  fi

  dir=$(wtp cd "$selected") || return 1
  echo "$dir"
  cd "$dir" || return 1
}

But with this branch's changes, it could simply be

selected=$(wtp list -q | fzf --prompt="Select branch: ")

LLM Disclosure

I noticed you had Claude tagged in the repository, so I'm hoping it's no imposition, but I did work on this change in Cursor with Sonnet 4.5. I reviewed and tested the code myself and happily give it my cosign.

Summary by CodeRabbit

  • New Features

    • Added --quiet / -q flag to the list command for simplified output: prints only worktree names one per line and suppresses output when no worktrees exist.
  • Bug Fixes / Improvements

    • Unified worktree naming logic so quiet and regular list views show consistent display names.
  • Tests

    • Added tests covering quiet-mode behavior (single, multiple, none, detached cases).

The --quiet / -q switch for the `list` subcommand provides scripting friendly output to the list subcommand, outputting only the values from the "PATH" column of the pre-existing output.
@coderabbitai
Copy link

coderabbitai bot commented Oct 21, 2025

Walkthrough

Adds a quiet mode flag (--quiet / -q) to the list command, extends listCommandWithCommandExecutor to accept a quiet bool, introduces getWorktreeDisplayName and displayWorktreesQuiet helpers, and updates tests to exercise quiet-mode outputs.

Changes

Cohort / File(s) Change Summary
Quiet Mode Feature
cmd/wtp/list.go
Adds --quiet / -q flag; extends listCommandWithCommandExecutor signature to include quiet bool; routes output to displayWorktreesQuiet when quiet; introduces getWorktreeDisplayName; unifies naming logic across display paths.
Test Coverage Updates
cmd/wtp/list_test.go
Updates test calls to pass the new quiet bool; adds tests for quiet-mode scenarios (single, multiple, none, detached-head) asserting one-name-per-line output and no headers.

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant ListCmd as listCommandWithCommandExecutor
  participant Executor as command.Executor
  participant DisplayQuiet as displayWorktreesQuiet
  participant DisplayRel as displayWorktreesRelative
  participant NameHelper as getWorktreeDisplayName

  CLI->>ListCmd: invoke list (with flags incl. quiet)
  ListCmd->>Executor: fetch worktrees
  Executor-->>ListCmd: worktree list
  alt quiet == true
    ListCmd->>DisplayQuiet: display names
    DisplayQuiet->>NameHelper: resolve names (per worktree)
    NameHelper-->>DisplayQuiet: name
    DisplayQuiet-->>ListCmd: output lines
  else quiet == false
    ListCmd->>DisplayRel: display table/relative paths
    DisplayRel->>NameHelper: resolve names (per worktree)
    NameHelper-->>DisplayRel: name
    DisplayRel-->>ListCmd: output table
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Quiet paws pat the code tonight,
Names hop out in a single line light,
Flags tucked in, helpers snug and neat,
Tests nod softly — the change is fleet.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "feat: add quiet mode to list subcommand" is concise, clear, and fully related to the main changes in the changeset. The implementation adds a --quiet / -q flag to the list command that produces scripting-friendly output by emitting only worktree names, which is exactly what the title describes. The title uses conventional commit format (feat:), avoids vague or generic terms, and provides sufficient specificity that a teammate scanning the history would immediately understand the primary change.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b76d15f and 8ba4a0a.

📒 Files selected for processing (1)
  • cmd/wtp/list.go (5 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*.go: Run gofmt and goimports; keep imports grouped and organized; local import prefix follows module path github.com/satococoa/wtp
Adhere to golangci-lint rules configured for the project (vet, staticcheck, gosec, mnd, lll=120, etc.)
Errors should be wrapped with context and must not be ignored
Use snake_case for Go filenames; document exported identifiers when non-trivial

Files:

  • cmd/wtp/list.go
cmd/wtp/**

📄 CodeRabbit inference engine (AGENTS.md)

cmd/wtp/**: CLI entrypoint and commands are implemented under cmd/wtp
Update CLI help text to reflect user-facing changes
Command behavior: wtp cd prints only the absolute worktree path with no side effects
Command behavior: wtp completion generates pure completion scripts via urfave/cli
Command behavior: wtp hook emits shell functions that intercept wtp cd; wtp shell-init combines completion and hook output

Files:

  • cmd/wtp/list.go
🧠 Learnings (1)
📚 Learning: 2025-10-07T15:56:11.510Z
Learnt from: CR
PR: satococoa/wtp#0
File: AGENTS.md:0-0
Timestamp: 2025-10-07T15:56:11.510Z
Learning: Applies to cmd/wtp/completion.go : Use getWorktreeNameFromPath() to resolve worktree display names consistently across completion, errors, and parsing

Applied to files:

  • cmd/wtp/list.go
🧬 Code graph analysis (1)
cmd/wtp/list.go (2)
internal/config/config.go (1)
  • Config (12-16)
internal/git/worktree.go (1)
  • Worktree (14-19)
🔇 Additional comments (5)
cmd/wtp/list.go (5)

55-61: LGTM! Clean flag definition.

The quiet flag follows standard CLI conventions with a clear usage description and the conventional -q alias.


94-99: LGTM! Correct flag propagation.

The quiet flag is read using the standard cmd.Bool() method and properly threaded through to the executor function.


122-133: LGTM! Appropriate behavior for quiet mode.

The conditional logic correctly suppresses informational messages and dispatches to the appropriate display function based on the quiet flag. This aligns with standard quiet-mode behavior for scripting-friendly output.


253-271: LGTM! Excellent refactoring and clean implementation.

The introduction of getWorktreeDisplayName consolidates naming logic and reduces duplication across both display modes. The function correctly uses getWorktreeNameFromPath for consistency (as per learnings) and provides appropriate fallbacks.

The displayWorktreesQuiet function produces clean, scripting-friendly output by emitting only worktree names without markers or formatting—exactly what's needed for pipelines with tools like fzf.

Based on learnings.


305-306: LGTM! Good refactoring for consistency.

Replacing inline naming logic with getWorktreeDisplayName ensures both quiet and non-quiet display modes use identical naming resolution, improving maintainability and consistency.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
cmd/wtp/list.go (1)

259-268: Consider extracting the config fallback logic.

The fallback logic when cfg is nil (lines 259-268) duplicates similar logic in displayWorktreesRelative (lines 308-317). If getWorktreeNameFromPath doesn't gracefully handle nil config, consider extracting this fallback pattern into a small helper function for DRY compliance.

Example helper:

// getWorktreeDisplayName returns the display name for a worktree, with fallback for nil config
func getWorktreeDisplayName(wt git.Worktree, cfg *config.Config, mainRepoPath string) string {
    if cfg != nil {
        return getWorktreeNameFromPath(wt.Path, cfg, mainRepoPath, wt.IsMain)
    }
    if wt.IsMain {
        return "@"
    }
    return filepath.Base(wt.Path)
}

Then both functions could call this helper, eliminating the duplication.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 780af9d and b76d15f.

📒 Files selected for processing (2)
  • cmd/wtp/list.go (4 hunks)
  • cmd/wtp/list_test.go (12 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*.go: Run gofmt and goimports; keep imports grouped and organized; local import prefix follows module path github.com/satococoa/wtp
Adhere to golangci-lint rules configured for the project (vet, staticcheck, gosec, mnd, lll=120, etc.)
Errors should be wrapped with context and must not be ignored
Use snake_case for Go filenames; document exported identifiers when non-trivial

Files:

  • cmd/wtp/list.go
  • cmd/wtp/list_test.go
cmd/wtp/**

📄 CodeRabbit inference engine (AGENTS.md)

cmd/wtp/**: CLI entrypoint and commands are implemented under cmd/wtp
Update CLI help text to reflect user-facing changes
Command behavior: wtp cd prints only the absolute worktree path with no side effects
Command behavior: wtp completion generates pure completion scripts via urfave/cli
Command behavior: wtp hook emits shell functions that intercept wtp cd; wtp shell-init combines completion and hook output

Files:

  • cmd/wtp/list.go
  • cmd/wtp/list_test.go
**/*_test.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*_test.go: Unit tests live alongside packages and use *_test.go naming
Prefer table-driven tests and mock git operations in unit tests

Files:

  • cmd/wtp/list_test.go
🧠 Learnings (1)
📚 Learning: 2025-10-07T15:56:11.510Z
Learnt from: CR
PR: satococoa/wtp#0
File: AGENTS.md:0-0
Timestamp: 2025-10-07T15:56:11.510Z
Learning: Applies to cmd/wtp/completion.go : Use getWorktreeNameFromPath() to resolve worktree display names consistently across completion, errors, and parsing

Applied to files:

  • cmd/wtp/list.go
🧬 Code graph analysis (2)
cmd/wtp/list.go (2)
internal/config/config.go (1)
  • Config (12-16)
internal/git/worktree.go (1)
  • Worktree (14-19)
cmd/wtp/list_test.go (2)
internal/command/types.go (2)
  • Result (11-15)
  • Command (4-8)
internal/config/config.go (2)
  • Config (12-16)
  • Defaults (19-21)
🔇 Additional comments (7)
cmd/wtp/list.go (5)

55-61: LGTM! Clean flag definition.

The --quiet / -q flag is well-defined with clear usage text. The alias matches the docker convention mentioned in the PR objectives.


94-99: LGTM! Proper flag retrieval and propagation.

The quiet flag is retrieved using the standard urfave/cli pattern and correctly propagated to the executor function.


103-103: LGTM! Function signature properly extended.

The quiet parameter is added to support the new mode. All test callers were correctly updated to pass this parameter.


122-133: LGTM! Clean conditional logic for quiet mode.

The implementation correctly:

  • Prints nothing in quiet mode when no worktrees exist (scripting-friendly)
  • Branches to the appropriate display function based on the quiet flag

253-272: LGTM! Well-implemented quiet mode output.

The function correctly outputs worktree names one per line, which is perfect for scripting workflows like the fzf pipeline mentioned in the PR objectives. The use of getWorktreeNameFromPath aligns with the learning about consistent worktree name resolution.

cmd/wtp/list_test.go (2)

114-114: LGTM! All existing tests properly updated.

All existing test calls were correctly updated to pass false for the new quiet parameter, maintaining their verification of non-quiet behavior.

Also applies to: 183-183, 228-228, 250-250, 311-311, 379-379, 460-460, 563-563, 705-705, 789-789


816-947: LGTM! Excellent test coverage for quiet mode.

The new quiet mode tests are comprehensive and well-structured:

  • Single worktree test: Verifies minimal output (@\n) with no headers
  • Multiple worktrees test: Confirms one-per-line format with correct worktree names
  • No worktrees test: Correctly expects empty output (not "No worktrees found" message)
  • Detached HEAD test: Verifies only worktree name is shown, not branch state

These tests thoroughly validate the scripting-friendly output format described in the PR objectives.

@bigs
Copy link
Contributor Author

bigs commented Oct 21, 2025

Solid nit feedback from the bot, hah. I went for it.

@satococoa
Copy link
Owner

@bigs cc/ @ox
The getWorktreeDisplayName extraction really tidies up the naming logic, and the added quiet-mode tests give great confidence.
Thanks for the solid improvement!

@satococoa satococoa merged commit a7c84fc into satococoa:main Oct 23, 2025
7 checks passed
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.

3 participants