|
| 1 | +# CLI / Non-Interactive Mode |
| 2 | + |
| 3 | +## Status: Live |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Command-line interface for scripting and non-TTY environments. |
| 8 | + |
| 9 | +## Requirements |
| 10 | + |
| 11 | +### Functional Requirements |
| 12 | + |
| 13 | +1. **TTY Detection** |
| 14 | + - Detect when stdin/stdout are not TTY |
| 15 | + - Automatically switch to non-interactive behavior |
| 16 | + |
| 17 | +2. **Usage Display (no arguments)** |
| 18 | + - Print usage information |
| 19 | + - List existing worktrees with paths |
| 20 | + - List branches without worktrees |
| 21 | + |
| 22 | +3. **Branch Switch (`git-wt [branch]`)** |
| 23 | + - Create worktree if doesn't exist |
| 24 | + - Print worktree path to stdout (for `cd "$(git-wt branch)"`) |
| 25 | + - Silent operation (no interactive prompts) |
| 26 | + |
| 27 | +4. **Exec Flags** |
| 28 | + - `--exec` - Spawn shell in worktree (override default) |
| 29 | + - `--no-exec` - Print path only (default in CLI mode) |
| 30 | + |
| 31 | +5. **Error Handling** |
| 32 | + - Exit with non-zero status on errors |
| 33 | + - Print errors to stderr |
| 34 | + |
| 35 | +### Non-Functional Requirements |
| 36 | + |
| 37 | +- No TTY required |
| 38 | +- No `fzf` or `gum` required |
| 39 | +- Suitable for scripting and automation |
| 40 | + |
| 41 | +## CLI Interface |
| 42 | + |
| 43 | +```bash |
| 44 | +# Print usage and list worktrees/branches |
| 45 | +git-wt |
| 46 | + |
| 47 | +# Switch to branch (prints path) |
| 48 | +git-wt feature-branch |
| 49 | + |
| 50 | +# Switch and spawn shell |
| 51 | +git-wt feature-branch --exec |
| 52 | + |
| 53 | +# Use in scripts |
| 54 | +cd "$(git-wt feature-branch)" |
| 55 | +``` |
| 56 | + |
| 57 | +## Output Format |
| 58 | + |
| 59 | +### Usage Output |
| 60 | +``` |
| 61 | +Usage: git-wt [branch] Switch to or create worktree |
| 62 | + git-wt d [branch] Delete worktree (requires --force) |
| 63 | +
|
| 64 | +Options: |
| 65 | + --exec Spawn shell in worktree (instead of printing path) |
| 66 | + --force Force deletion without confirmation |
| 67 | +
|
| 68 | +Examples: |
| 69 | + cd "$(git-wt feature-branch)" # Switch to worktree |
| 70 | + git-wt feature-branch --exec # Switch and spawn shell |
| 71 | + git-wt d feature-branch --force # Delete worktree |
| 72 | +
|
| 73 | +Worktrees: |
| 74 | + [root] main → /path/to/repo |
| 75 | + [worktree] feature-1 → /path/to/repo.worktrees/feature-1 |
| 76 | +
|
| 77 | +Branches (without worktrees): |
| 78 | + feature-2 |
| 79 | + bugfix-3 |
| 80 | +``` |
| 81 | + |
| 82 | +### Switch Output (--no-exec, default) |
| 83 | +``` |
| 84 | +/path/to/repo.worktrees/feature-branch |
| 85 | +``` |
| 86 | + |
| 87 | +## Implementation Notes |
| 88 | + |
| 89 | +- Fetch from origin happens silently |
| 90 | +- New branches base off default branch without prompting |
| 91 | +- Upgrade notice suppressed in non-interactive mode |
0 commit comments