Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat: Add global `-C` flag to change working directory

Maximilian Roos95db7bc867e7
diff --git a/src/cli.rs b/src/cli.rs
index d08723373..015d8ced4 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -35,6 +35,10 @@ pub enum OutputFormat {
#[command(version = version_str())]
#[command(disable_help_subcommand = true)]
pub struct Cli {
+ /// Run as if worktrunk was started in `<path>` instead of the current working directory
+ #[arg(short = 'C', global = true, value_name = "path")]
+ pub directory: Option<std::path::PathBuf>,
+
/// Enable verbose output (show git commands and debug info)
#[arg(long, short = 'v', global = true)]
pub verbose: bool,
diff --git a/src/git/mod.rs b/src/git/mod.rs
index 7bb68f252..8b9735183 100644
--- a/src/git/mod.rs
+++ b/src/git/mod.rs
@@ -31,7 +31,7 @@ static HEAVY_OPS_SEMAPHORE: LazyLock<semaphore::Semaphore> =
// Re-exports from submodules
pub use diff::{DiffStats, LineDiff};
pub use error::GitError;
-pub use repository::{GitResultExt, Repository};
+pub use repository::{GitResultExt, Repository, set_base_path};
// Re-export parsing helpers for internal use
pub(crate) use parse::DefaultBranchName;
diff --git a/src/git/repository/mod.rs b/src/git/repository/mod.rs
index 81cf06d0d..43b231f64 100644
--- a/src/git/repository/mod.rs
+++ b/src/git/repository/mod.rs
@@ -8,6 +8,25 @@ use super::{
DefaultBranchName, DiffStats, GitError, LineDiff, SwitchHistory, Worktree, WorktreeList,
};
+/// Global base path for repository operations, set by -C flag
+static BASE_PATH: OnceLock<PathBuf> = OnceLock::new();
+
+/// Initialize the global base path for repository operations.
+///
+/// This should be called once at program startup from main().
+/// If not called, defaults to "." (current directory).
+pub fn set_base_path(path: PathBuf) {
+ BASE_PATH.set(path).ok();
+}
+
+/// Get the base path for repository operations.
+fn base_path() -> &'static PathBuf {
+ static DEFAULT: OnceLock<PathBuf> = OnceLock::new();
+ BASE_PATH
+ .get()
+ .unwrap_or_else(|| DEFAULT.get_or_init(|| PathBuf::from(".")))
+}
+
/// Extension trait for Result types to simplify GitError conversions
///
/// This trait provides ergonomic methods to convert any Result into Result<T, GitError>.
@@ -95,9 +114,10 @@ impl Repository {
/// Create a repository context for the current directory.
///
- /// This is the most common usage pattern.
+ /// This is the most common usage pattern. If the -C flag was used,
+ /// this uses that path instead of the actual current directory.
pub fn current() -> Self {
- Self::at(".")
+ Self::at(base_path().clone())
}
/// Get the path this repository context operates on.
diff --git a/src/main.rs b/src/main.rs
index 1e3c0cc0f..26650b15d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,7 +2,7 @@ use anstyle::Style;
use clap::{CommandFactory, Parser};
use std::process;
use worktrunk::config::WorktrunkConfig;
-use worktrunk::git::{GitError, GitResultExt, Repository};
+use worktrunk::git::{GitError, GitResultExt, Repository, set_base_path};
use worktrunk::styling::{SUCCESS_EMOJI, println};
mod cli;
@@ -40,6 +40,11 @@ fn main() {
// MissingRequiredArgument errors and print custom messages with ValueEnum::value_variants().
let cli = Cli::parse();
+ // Initialize base path from -C flag if provided
+ if let Some(path) = cli.directory {
+ set_base_path(path);
+ }
+
// Initialize output context based on --internal flag
let output_mode = if cli.internal {
output::OutputMode::Directive
diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rs
index 1f61e69ac..8fceeb033 100644
--- a/tests/integration_tests/list.rs
+++ b/tests/integration_tests/list.rs
@@ -744,3 +744,23 @@ fn test_readme_example_simple_list() {
snapshot_list("readme_example_simple_list", &repo);
}
+
+#[test]
+fn test_list_with_c_flag() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Create some worktrees
+ repo.add_worktree("feature-a", "feature-a");
+ repo.add_worktree("feature-b", "feature-b");
+
+ // Run wt -C <repo_path> list from a completely different directory
+ let settings = list_snapshots::standard_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ cmd.args(["-C", repo.root_path().to_str().unwrap(), "list"]);
+ // Run from /tmp to ensure -C is actually being used
+ cmd.current_dir("/tmp");
+ assert_cmd_snapshot!("list_with_c_flag", cmd);
+ });
+}
diff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snap
index 3f924f4ee..7fa6d133c 100644
--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap
@@ -1,6 +1,5 @@
---
source: tests/integration_tests/init.rs
-assertion_line: 23
info:
program: wt
args:
@@ -13,10 +12,11 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmps2V6eB/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpwOlI4n/test-config.toml
---
success: true
exit_code: 0
@@ -221,12 +221,16 @@ _wt() {
case "${cmd}" in
wt)
- opts="-v -h -V --verbose --help --version init config beta list switch remove merge"
+ opts="-C -v -h -V --verbose --help --version init config beta list switch remove merge"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -235,12 +239,16 @@ _wt() {
return 0
;;
wt__beta)
- opts="-v -h --verbose --help run-hook commit squash push rebase ask-approvals clear-approvals select"
+ opts="-C -v -h --verbose --help run-hook commit squash push rebase ask-approvals clear-approvals select"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -249,12 +257,16 @@ _wt() {
return 0
;;
wt__beta__ask__approvals)
- opts="-f -v -h --force --all --verbose --help"
+ opts="-f -C -v -h --force --all --verbose --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -263,12 +275,16 @@ _wt() {
return 0
;;
wt__beta__clear__approvals)
- opts="-g -v -h --global --verbose --help"
+ opts="-g -C -v -h --global --verbose --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -277,12 +293,16 @@ _wt() {
return 0
;;
wt__beta__commit)
- opts="-f -v -h --force --no-verify --verbose --help"
+ opts="-f -C -v -h --force --no-verify --verbose --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -291,12 +311,16 @@ _wt() {
return 0
;;
wt__beta__push)
- opts="-v -h --allow-merge-commits --verbose --help [TARGET]"
+ opts="-C -v -h --allow-merge-commits --verbose --help [TARGET]"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -305,12 +329,16 @@ _wt() {
return 0
;;
wt__beta__rebase)
- opts="-v -h --verbose --help [TARGET]"
+ opts="-C -v -h --verbose --help [TARGET]"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -319,12 +347,16 @@ _wt() {
return 0
;;
wt__beta__run__hook)
- opts="-f -v -h --force --verbose --help post-create post-start pre-commit pre-merge post-merge"
+ opts="-f -C -v -h --force --verbose --help post-create post-start pre-commit pre-merge post-merge"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -333,12 +365,16 @@ _wt() {
return 0
;;
wt__beta__select)
- opts="-v -h --verbose --help"
+ opts="-C -v -h --verbose --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -347,12 +383,16 @@ _wt() {
return 0
;;
wt__beta__squash)
- opts="-f -v -h --force --no-verify --verbose --help [TARGET]"
+ opts="-f -C -v -h --force --no-verify --verbose --help [TARGET]"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -361,12 +401,16 @@ _wt() {
return 0
;;
wt__config)
- opts="-v -h --verbose --help init list refresh-cache shell"
+ opts="-C -v -h --verbose --help init list refresh-cache shell"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -375,12 +419,16 @@ _wt() {
return 0
;;
wt__config__init)
- opts="-v -h --verbose --help"
+ opts="-C -v -h --verbose --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -389,12 +437,16 @@ _wt() {
return 0
;;
wt__config__list)
- opts="-v -h --verbose --help"
+ opts="-C -v -h --verbose --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -403,12 +455,16 @@ _wt() {
return 0
;;
wt__config__refresh__cache)
- opts="-v -h --verbose --help"
+ opts="-C -v -h --verbose --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -417,7 +473,7 @@ _wt() {
return 0
;;
wt__config__shell)
- opts="-f -v -h --shell --force --command-name --verbose --help"
+ opts="-f -C -v -h --shell --force --command-name --verbose --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
@@ -431,6 +487,10 @@ _wt() {
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -439,7 +499,7 @@ _wt() {
return 0
;;
wt__init)
- opts="-v -h --command-name --verbose --help bash elvish fish nushell oil powershell xonsh zsh"
+ opts="-C -v -h --command-name --verbose --help bash elvish fish nushell oil powershell xonsh zsh"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
@@ -449,6 +509,10 @@ _wt() {
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -457,7 +521,7 @@ _wt() {
return 0
;;
wt__list)
- opts="-v -h --format --branches --full --verbose --help"
+ opts="-C -v -h --format --branches --full --verbose --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
@@ -467,6 +531,10 @@ _wt() {
COMPREPLY=($(compgen -W "table json" -- "${cur}"))
return 0
;;
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -475,12 +543,16 @@ _wt() {
return 0
;;
wt__merge)
- opts="-f -v -h --no-squash --no-commit --no-remove --no-verify --force --tracked-only --verbose --help [TARGET]"
+ opts="-f -C -v -h --no-squash --no-commit --no-remove --no-verify --force --tracked-only --verbose --help [TARGET]"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -489,12 +561,16 @@ _wt() {
return 0
;;
wt__remove)
- opts="-v -h --no-delete-branch --verbose --help [WORKTREES]..."
+ opts="-C -v -h --no-delete-branch --verbose --help [WORKTREES]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
@@ -503,7 +579,7 @@ _wt() {
return 0
;;
wt__switch)
- opts="-c -b -x -f -v -h --create --base --execute --force --no-verify --verbose --help <BRANCH>"
+ opts="-c -b -x -f -C -v -h --create --base --execute --force --no-verify --verbose --help <BRANCH>"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
@@ -525,6 +601,10 @@ _wt() {
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
+ -C)
+ COMPREPLY=($(compgen -f "${cur}"))
+ return 0
+ ;;
*)
COMPREPLY=()
;;
diff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snap
index 3207879db..54dea9e81 100644
--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap
@@ -16,7 +16,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp5Ozdm0/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpsRi5vV/test-config.toml
---
success: true
exit_code: 0
@@ -159,7 +159,7 @@ end
# Static completions (commands and flags)
# Print an optspec for argparse to handle cmd's options that are independent of any subcommand.
function __fish_wt_global_optspecs
- string join \n source v/verbose internal h/help V/version
+ string join \n C= v/verbose internal h/help V/version
end
function __fish_wt_needs_command
@@ -183,6 +183,7 @@ function __fish_wt_using_subcommand
contains -- $cmd[1] $argv
end
+complete -c wt -n "__fish_wt_needs_command" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_needs_command" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_needs_command" -s h -l help -d 'Print help'
complete -c wt -n "__fish_wt_needs_command" -s V -l version -d 'Print version'
@@ -194,18 +195,23 @@ complete -c wt -n "__fish_wt_needs_command" -f -a "switch" -d 'Switch to a workt
complete -c wt -n "__fish_wt_needs_command" -f -a "remove" -d 'Finish current worktree, returning to primary if current'
complete -c wt -n "__fish_wt_needs_command" -f -a "merge" -d 'Merge worktree into target branch'
complete -c wt -n "__fish_wt_using_subcommand init" -l command-name -d 'Command name to use (defaults to \'wt\')' -r
+complete -c wt -n "__fish_wt_using_subcommand init" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand init" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand init" -s h -l help -d 'Print help'
+complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from init list refresh-cache shell" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from init list refresh-cache shell" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from init list refresh-cache shell" -s h -l help -d 'Print help (see more with \'--help\')'
complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from init list refresh-cache shell" -f -a "init" -d 'Initialize global configuration file with examples'
complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from init list refresh-cache shell" -f -a "list" -d 'List all configuration files and their locations'
complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from init list refresh-cache shell" -f -a "refresh-cache" -d 'Refresh the cached default branch by querying the remote'
complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from init list refresh-cache shell" -f -a "shell" -d 'Configure shell by writing to config files'
+complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from init" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from init" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from init" -s h -l help -d 'Print help'
+complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from list" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from list" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from list" -s h -l help -d 'Print help'
+complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from refresh-cache" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from refresh-cache" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from refresh-cache" -s h -l help -d 'Print help'
complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -l shell -d 'Specific shell to configure (default: all shells with existing config files)' -r -f -a "bash\t''
@@ -217,9 +223,11 @@ powershell\t''
xonsh\t''
zsh\t''"
complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -l command-name -d 'Command name to use (defaults to \'wt\')' -r
+complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -s f -l force -d 'Skip confirmation prompt'
complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -s h -l help -d 'Print help (see more with \'--help\')'
+complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -s h -l help -d 'Print help'
complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "run-hook" -d 'Run a project hook for testing'
@@ -230,47 +238,59 @@ complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcomma
complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "ask-approvals" -d 'Approve commands in the project config (shows unapproved by default)'
complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "clear-approvals" -d 'Clear approved commands from config'
complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "select" -d 'Interactive worktree selector'
+complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from run-hook" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from run-hook" -s f -l force -d 'Auto-approve project commands without saving approvals'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from run-hook" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from run-hook" -s h -l help -d 'Print help'
+complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from commit" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from commit" -s f -l force -d 'Auto-approve project commands without saving approvals'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from commit" -l no-verify -d 'Skip pre-commit project hooks'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from commit" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from commit" -s h -l help -d 'Print help'
+complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from squash" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from squash" -s f -l force -d 'Auto-approve project commands without saving approvals'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from squash" -l no-verify -d 'Skip pre-commit project hooks'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from squash" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from squash" -s h -l help -d 'Print help'
+complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from push" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from push" -l allow-merge-commits -d 'Allow pushing merge commits (non-linear history)'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from push" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from push" -s h -l help -d 'Print help (see more with \'--help\')'
+complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from rebase" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from rebase" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from rebase" -s h -l help -d 'Print help'
+complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -s f -l force -d 'Auto-approve project commands without saving approvals'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -l all -d 'Show all commands including already-approved ones'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -s h -l help -d 'Print help'
+complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from clear-approvals" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from clear-approvals" -s g -l global -d 'Clear approvals from global config (all projects)'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from clear-approvals" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from clear-approvals" -s h -l help -d 'Print help'
+complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from select" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from select" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from select" -s h -l help -d 'Print help (see more with \'--help\')'
complete -c wt -n "__fish_wt_using_subcommand list" -l format -d 'Output format' -r -f -a "table\t'Human-readable table format'
json\t'Machine-readable JSON with display fields (includes styled unicode for rendering)'"
+complete -c wt -n "__fish_wt_using_subcommand list" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand list" -l branches -d 'Include branches without worktrees'
complete -c wt -n "__fish_wt_using_subcommand list" -l full -d 'Show CI status, conflict detection, and complete diff statistics'
complete -c wt -n "__fish_wt_using_subcommand list" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand list" -s h -l help -d 'Print help (see more with \'--help\')'
complete -c wt -n "__fish_wt_using_subcommand switch" -s b -l base -f -d 'Base branch to create from (only with --create). Use \'@\' for current HEAD' -r
complete -c wt -n "__fish_wt_using_subcommand switch" -s x -l execute -d 'Execute command after switching' -r
+complete -c wt -n "__fish_wt_using_subcommand switch" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand switch" -s c -l create -d 'Create a new branch'
complete -c wt -n "__fish_wt_using_subcommand switch" -s f -l force -d 'Auto-approve project commands without saving approvals'
complete -c wt -n "__fish_wt_using_subcommand switch" -l no-verify -d 'Skip all project hooks: post-create and post-start'
complete -c wt -n "__fish_wt_using_subcommand switch" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand switch" -s h -l help -d 'Print help'
+complete -c wt -n "__fish_wt_using_subcommand remove" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand remove" -l no-delete-branch -d 'Don\'t delete the branch after removing the worktree (by default, branches are deleted)'
complete -c wt -n "__fish_wt_using_subcommand remove" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)'
complete -c wt -n "__fish_wt_using_subcommand remove" -s h -l help -d 'Print help'
+complete -c wt -n "__fish_wt_using_subcommand merge" -s C -d 'Run as if worktrunk was started in <path> instead of the current working directory' -r -F
complete -c wt -n "__fish_wt_using_subcommand merge" -l no-squash -d 'Disable squashing commits (by default, commits are squashed into one before merging)'
complete -c wt -n "__fish_wt_using_subcommand merge" -l no-commit -d 'Push commits as-is without transformations (requires clean tree; implies --no-squash, --no-remove, and skips rebase)'
complete -c wt -n "__fish_wt_using_subcommand merge" -l no-remove -d 'Keep the worktree after merging'
diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
index 2fee3fab7..a889208d0 100644
--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
@@ -1,6 +1,5 @@
---
source: tests/integration_tests/init.rs
-assertion_line: 23
info:
program: wt
args:
@@ -13,10 +12,11 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpQyAnKf/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpdfMHP8/test-config.toml
---
success: true
exit_code: 0
@@ -158,6 +158,7 @@ _wt() {
local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" : \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'-v[Enable verbose output (show git commands and debug info)]' \
'--verbose[Enable verbose output (show git commands and debug info)]' \
'-h[Print help]' \
@@ -176,6 +177,7 @@ _wt() {
(init)
_arguments "${_arguments_options[@]}" : \
'--command-name=[Command name to use (defaults to '\''wt'\'')]:COMMAND_NAME:_default' \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'-v[Enable verbose output (show git commands and debug info)]' \
'--verbose[Enable verbose output (show git commands and debug info)]' \
'-h[Print help]' \
@@ -185,6 +187,7 @@ _arguments "${_arguments_options[@]}" : \
;;
(config)
_arguments "${_arguments_options[@]}" : \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'-v[Enable verbose output (show git commands and debug info)]' \
'--verbose[Enable verbose output (show git commands and debug info)]' \
'-h[Print help (see more with '\''--help'\'')]' \
@@ -201,6 +204,7 @@ _arguments "${_arguments_options[@]}" : \
case $line[1] in
(init)
_arguments "${_arguments_options[@]}" : \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'-v[Enable verbose output (show git commands and debug info)]' \
'--verbose[Enable verbose output (show git commands and debug info)]' \
'-h[Print help]' \
@@ -209,6 +213,7 @@ _arguments "${_arguments_options[@]}" : \
;;
(list)
_arguments "${_arguments_options[@]}" : \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'-v[Enable verbose output (show git commands and debug info)]' \
'--verbose[Enable verbose output (show git commands and debug info)]' \
'-h[Print help]' \
@@ -217,6 +222,7 @@ _arguments "${_arguments_options[@]}" : \
;;
(refresh-cache)
_arguments "${_arguments_options[@]}" : \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'-v[Enable verbose output (show git commands and debug info)]' \
'--verbose[Enable verbose output (show git commands and debug info)]' \
'-h[Print help]' \
@@ -227,6 +233,7 @@ _arguments "${_arguments_options[@]}" : \
_arguments "${_arguments_options[@]}" : \
'--shell=[Specific shell to configure (default\: all shells with existing config files)]:SHELL:(bash elvish fish nushell oil powershell xonsh zsh)' \
'--command-name=[Command name to use (defaults to '\''wt'\'')]:COMMAND_NAME:_default' \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'-f[Skip confirmation prompt]' \
'--force[Skip confirmation prompt]' \
'-v[Enable verbose output (show git commands and debug info)]' \
@@ -241,6 +248,7 @@ esac
;;
(beta)
_arguments "${_arguments_options[@]}" : \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'-v[Enable verbose output (show git commands and debug info)]' \
'--verbose[Enable verbose output (show git commands and debug info)]' \
'-h[Print help]' \
@@ -257,6 +265,7 @@ _arguments "${_arguments_options[@]}" : \
case $line[1] in
(run-hook)
_arguments "${_arguments_options[@]}" : \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'-f[Auto-approve project commands without saving approvals]' \
'--force[Auto-approve project commands without saving approvals]' \
'-v[Enable verbose output (show git commands and debug info)]' \
@@ -268,6 +277,7 @@ _arguments "${_arguments_options[@]}" : \
;;
(commit)
_arguments "${_arguments_options[@]}" : \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'-f[Auto-approve project commands without saving approvals]' \
'--force[Auto-approve project commands without saving approvals]' \
'--no-verify[Skip pre-commit project hooks]' \
@@ -279,6 +289,7 @@ _arguments "${_arguments_options[@]}" : \
;;
(squash)
_arguments "${_arguments_options[@]}" : \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'-f[Auto-approve project commands without saving approvals]' \
'--force[Auto-approve project commands without saving approvals]' \
'--no-verify[Skip pre-commit project hooks]' \
@@ -291,6 +302,7 @@ _arguments "${_arguments_options[@]}" : \
;;
(push)
_arguments "${_arguments_options[@]}" : \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'--allow-merge-commits[Allow pushing merge commits (non-linear history)]' \
'-v[Enable verbose output (show git commands and debug info)]' \
'--verbose[Enable verbose output (show git commands and debug info)]' \
@@ -301,6 +313,7 @@ _arguments "${_arguments_options[@]}" : \
;;
(rebase)
_arguments "${_arguments_options[@]}" : \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'-v[Enable verbose output (show git commands and debug info)]' \
'--verbose[Enable verbose output (show git commands and debug info)]' \
'-h[Print help]' \
@@ -310,6 +323,7 @@ _arguments "${_arguments_options[@]}" : \
;;
(ask-approvals)
_arguments "${_arguments_options[@]}" : \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'-f[Auto-approve project commands without saving approvals]' \
'--force[Auto-approve project commands without saving approvals]' \
'--all[Show all commands including already-approved ones]' \
@@ -321,6 +335,7 @@ _arguments "${_arguments_options[@]}" : \
;;
(clear-approvals)
_arguments "${_arguments_options[@]}" : \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'-g[Clear approvals from global config (all projects)]' \
'--global[Clear approvals from global config (all projects)]' \
'-v[Enable verbose output (show git commands and debug info)]' \
@@ -331,6 +346,7 @@ _arguments "${_arguments_options[@]}" : \
;;
(select)
_arguments "${_arguments_options[@]}" : \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'-v[Enable verbose output (show git commands and debug info)]' \
'--verbose[Enable verbose output (show git commands and debug info)]' \
'-h[Print help (see more with '\''--help'\'')]' \
@@ -345,6 +361,7 @@ esac
_arguments "${_arguments_options[@]}" : \
'--format=[Output format]:FORMAT:((table\:"Human-readable table format"
json\:"Machine-readable JSON with display fields (includes styled unicode for rendering)"))' \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'--branches[Include branches without worktrees]' \
'--full[Show CI status, conflict detection, and complete diff statistics]' \
'-v[Enable verbose output (show git commands and debug info)]' \
@@ -359,6 +376,7 @@ _arguments "${_arguments_options[@]}" : \
'--base=[Base branch to create from (only with --create). Use '\''@'\'' for current HEAD]:BASE:_default' \
'-x+[Execute command after switching]:EXECUTE:_default' \
'--execute=[Execute command after switching]:EXECUTE:_default' \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'-c[Create a new branch]' \
'--create[Create a new branch]' \
'-f[Auto-approve project commands without saving approvals]' \
@@ -373,6 +391,7 @@ _arguments "${_arguments_options[@]}" : \
;;
(remove)
_arguments "${_arguments_options[@]}" : \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'--no-delete-branch[Don'\''t delete the branch after removing the worktree (by default, branches are deleted)]' \
'-v[Enable verbose output (show git commands and debug info)]' \
'--verbose[Enable verbose output (show git commands and debug info)]' \
@@ -383,6 +402,7 @@ _arguments "${_arguments_options[@]}" : \
;;
(merge)
_arguments "${_arguments_options[@]}" : \
+'-C+[Run as if worktrunk was started in <path> instead of the current working directory]:path:_files' \
'--no-squash[Disable squashing commits (by default, commits are squashed into one before merging)]' \
'--no-commit[Push commits as-is without transformations (requires clean tree; implies --no-squash, --no-remove, and skips rebase)]' \
'--no-remove[Keep the worktree after merging]' \
diff --git a/tests/snapshots/integration__integration_tests__list__list_with_c_flag.snap b/tests/snapshots/integration__integration_tests__list__list_with_c_flag.snap
new file mode 100644
index 000000000..67cb0a989
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__list__list_with_c_flag.snap
@@ -0,0 +1,24 @@
+---
+source: tests/integration_tests/list.rs
+info:
+ program: wt
+ args:
+ - "-C"
+ - /private/var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpo4Vz4F/test-repo
+ - list
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_EDITOR: ""
+---
+success: true
+exit_code: 0
+----- stdout -----
+Branch Status HEAD± main↕ Path Remote⇅ Commit Age Message
+main ./test-repo b834638e 10 months ago Initial commit
+feature-a ≡ ./feature-a b834638e 10 months ago Initial commit
+feature-b ≡ ./feature-b b834638e 10 months ago Initial commit
+
+⚪ Showing 3 worktrees
+
+----- stderr -----