Skip to content

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

feat(git): Infer default branch when remote is absent

Maximilian Roos3d577e8f200c
diff --git a/src/git.rs b/src/git.rs
index b42e2f69e..d4e97bd3d 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -402,15 +402,82 @@ impl Repository {
/// 1. Try local cache (`git rev-parse origin/HEAD`) first - fast, no network
/// 2. If not cached, query remote (`git ls-remote`) - may take 100ms-2s depending on network
/// 3. Cache the result (`git remote set-head`) for future invocations
+ /// 4. If no remote available, infer from local branches (no caching, shows hint)
pub fn default_branch(&self) -> Result<String, GitError> {
- let remote = self.primary_remote()?;
- // Try local cache first (fast path)
- self.get_local_default_branch(&remote).or_else(|_| {
+ // Try to get default branch from remote
+ if let Ok(remote) = self.primary_remote() {
+ // Try local cache first (fast path)
+ if let Ok(branch) = self.get_local_default_branch(&remote) {
+ return Ok(branch);
+ }
+
// Query remote and cache it
- let branch = self.query_remote_default_branch(&remote)?;
- self.cache_default_branch(&remote, &branch)?;
- Ok(branch)
- })
+ if let Ok(branch) = self.query_remote_default_branch(&remote) {
+ let _ = self.cache_default_branch(&remote, &branch);
+ return Ok(branch);
+ }
+ }
+
+ // Fallback: No remote or remote query failed, try to infer locally
+ // TODO: Show message to user when using inference fallback:
+ // "No remote configured. Using inferred default branch: {branch}"
+ // "To cache the default branch, set up a remote and run: wt config refresh-cache"
+ // Problem: git.rs is in lib crate, output module is in binary.
+ // Options: (1) Return info about whether fallback was used, let callers show message
+ // (2) Add messages in specific commands (merge.rs, worktree.rs)
+ // (3) Move output abstraction to lib crate
+ self.infer_default_branch_locally()
+ }
+
+ /// Infer the default branch locally (without remote).
+ ///
+ /// Uses local heuristics when no remote is available:
+ /// 1. If only one local branch exists, use it
+ /// 2. Check what HEAD points to (current branch in main worktree)
+ /// 3. Check user's git config init.defaultBranch
+ /// 4. Look for common branch names (main, master, develop)
+ /// 5. Fail if none of the above work
+ fn infer_default_branch_locally(&self) -> Result<String, GitError> {
+ // 1. If there's only one local branch, use it
+ let branches = self.local_branches()?;
+ if branches.len() == 1 {
+ return Ok(branches[0].clone());
+ }
+
+ // 2. Use the branch HEAD points to (from main worktree)
+ // This is what the main worktree is currently on
+ if let Ok(current) = self.run_command(&["symbolic-ref", "--short", "HEAD"]) {
+ let branch = current.trim().to_string();
+ if !branch.is_empty() {
+ return Ok(branch);
+ }
+ }
+
+ // 3. Check git config init.defaultBranch
+ if let Ok(default) = self.run_command(&["config", "--get", "init.defaultBranch"]) {
+ let branch = default.trim().to_string();
+ if !branch.is_empty() && branches.contains(&branch) {
+ return Ok(branch);
+ }
+ }
+
+ // 4. Look for common branch names
+ for name in ["main", "master", "develop", "trunk"] {
+ if branches.contains(&name.to_string()) {
+ return Ok(name.to_string());
+ }
+ }
+
+ // 5. Give up - can't infer
+ Err(GitError::CommandFailed(
+ "Could not infer default branch. Please specify target branch explicitly or set up a remote.".to_string()
+ ))
+ }
+
+ /// List all local branches.
+ fn local_branches(&self) -> Result<Vec<String>, GitError> {
+ let stdout = self.run_command(&["branch", "--format=%(refname:short)"])?;
+ Ok(stdout.lines().map(|s| s.trim().to_string()).collect())
}
/// Get the git common directory (the actual .git directory for the repository).
diff --git a/tests/integration_tests/default_branch.rs b/tests/integration_tests/default_branch.rs
index f7923e074..1b2e8696e 100644
--- a/tests/integration_tests/default_branch.rs
+++ b/tests/integration_tests/default_branch.rs
@@ -65,9 +65,18 @@ fn test_get_default_branch_no_remote() {
let repo = TestRepo::new();
repo.commit("Initial commit");
- // No remote configured, should fail
+ // No remote configured, should infer from local branches
+ // Since there's only one local branch, it should return that
let result = Repository::at(repo.root_path()).default_branch();
- assert!(result.is_err());
+ assert!(result.is_ok());
+
+ // The inferred branch should match the current branch
+ let inferred_branch = result.unwrap();
+ let current_branch = Repository::at(repo.root_path())
+ .current_branch()
+ .expect("Failed to get current branch")
+ .expect("Should have a current branch");
+ assert_eq!(inferred_branch, current_branch);
}
#[test]
diff --git a/tests/integration_tests/directives.rs b/tests/integration_tests/directives.rs
index 82dc84950..288be9c09 100644
--- a/tests/integration_tests/directives.rs
+++ b/tests/integration_tests/directives.rs
@@ -80,18 +80,7 @@ fn test_remove_internal_directive() {
.arg("remove")
.current_dir(repo.root_path());
- assert_cmd_snapshot!(cmd, @r"
- success: false
- exit_code: 1
- ----- stdout -----
-
- ----- stderr -----
- fatal: 'origin' does not appear to be a git repository
- fatal: Could not read from remote repository.
-
- Please make sure you have the correct access rights
- and the repository exists.
- ");
+ assert_cmd_snapshot!(cmd, @"success: true\nexit_code: 0\n----- stdout -----\n✅ \u{1b}[32mAlready on default branch \u{1b}[1m\u{1b}[32mmain\u{1b}[0m\u{1b}[0m\0\n----- stderr -----");
});
}
@@ -110,16 +99,12 @@ fn test_remove_without_internal() {
cmd.arg("remove").current_dir(repo.root_path());
assert_cmd_snapshot!(cmd, @r"
- success: false
- exit_code: 1
+ success: true
+ exit_code: 0
----- stdout -----
+ ✅ Already on default branch main
----- stderr -----
- fatal: 'origin' does not appear to be a git repository
- fatal: Could not read from remote repository.
-
- Please make sure you have the correct access rights
- and the repository exists.
");
});
}
diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rs
index 084c8806c..71c844b18 100644
--- a/tests/integration_tests/merge.rs
+++ b/tests/integration_tests/merge.rs
@@ -1542,3 +1542,31 @@ fn test_merge_pre_squash_command_failure() {
Some(&feature_wt),
);
}
+
+#[test]
+fn test_merge_no_remote() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+ // Deliberately NOT calling setup_remote to test the error case
+
+ // Create a feature worktree and make a commit
+ let feature_wt = repo.add_worktree("feature", "feature");
+ fs::write(feature_wt.join("feature.txt"), "feature content").expect("Failed to write file");
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["add", "feature.txt"])
+ .current_dir(&feature_wt)
+ .output()
+ .expect("Failed to add file");
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["commit", "-m", "Add feature file"])
+ .current_dir(&feature_wt)
+ .output()
+ .expect("Failed to commit");
+
+ // Try to merge without specifying target (should fail - no remote to get default branch)
+ snapshot_merge("merge_no_remote", &repo, &[], Some(&feature_wt));
+}
diff --git a/tests/integration_tests/push.rs b/tests/integration_tests/push.rs
index 3b726f147..556a7cf52 100644
--- a/tests/integration_tests/push.rs
+++ b/tests/integration_tests/push.rs
@@ -294,3 +294,32 @@ fn test_push_error_with_merge_commits() {
Some(&feature_wt),
);
}
+
+#[test]
+fn test_push_no_remote() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+ // Deliberately NOT calling setup_remote to test the error case
+
+ // Create a feature worktree and make a commit
+ let feature_wt = repo.add_worktree("feature", "feature");
+ std::fs::write(feature_wt.join("feature.txt"), "feature content")
+ .expect("Failed to write file");
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["add", "feature.txt"])
+ .current_dir(&feature_wt)
+ .output()
+ .expect("Failed to add file");
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["commit", "-m", "Add feature file"])
+ .current_dir(&feature_wt)
+ .output()
+ .expect("Failed to commit");
+
+ // Try to push without specifying target (should fail - no remote to get default branch)
+ snapshot_push("push_no_remote", &repo, &[], Some(&feature_wt));
+}
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks.snap
deleted file mode 100644
index 64c1da482..000000000
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks.snap
+++ /dev/null
@@ -1,21 +0,0 @@
----
-source: tests/integration_tests/shell_wrapper.rs
-expression: output.normalized().as_ref()
----
-🔄 Running post-create: 1
-  echo 'Installing dependencies...'
-
-Installing dependencies...
-
-🔄 Running post-create: 2
-  echo 'Building project...'
-
-Building project...
-
-🔄 Running post-start: server
-  echo 'Starting dev server on port 3000'
-
-🔄 Running post-start: watch
-  echo 'Watching for file changes'
-
-✅ Created new worktree for feature-hooks, changed directory to [TMPDIR]/test-repo.feature-hooks
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_fish.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_fish.snap
deleted file mode 100644
index 73e1da98d..000000000
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_hooks_fish.snap
+++ /dev/null
@@ -1,19 +0,0 @@
----
-source: tests/integration_tests/shell_wrapper.rs
-expression: output.normalized().as_ref()
----
-🔄 Running post-create: 1
-  echo 'Installing dependencies...'
-
-Installing dependencies...
-🔄 Running post-create: 2
-  echo 'Building project...'
-
-Building project...
-🔄 Running post-start: server
-  echo 'Starting dev server on port 3000'
-
-🔄 Running post-start: watch
-  echo 'Watching for file changes'
-
-✅ Created new worktree for feature-hooks, changed directory to [TMPDIR]/test-repo.feature-hooks
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index ff70cdc5d..4c6576639 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -358,3 +358,13 @@ fn test_switch_no_config_commands_with_force() {
&[],
);
}
+
+#[test]
+fn test_switch_create_no_remote() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+ // Deliberately NOT calling setup_remote to test the error case
+
+ // Try to create a branch without specifying base (should fail - no remote to get default branch)
+ snapshot_switch("switch_create_no_remote", &repo, &["--create", "feature"]);
+}
diff --git a/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap b/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap
deleted file mode 100644
index d33ba5b4e..000000000
--- a/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap
+++ /dev/null
@@ -1,478 +0,0 @@
----
-source: tests/integration_tests/init.rs
-info:
- program: wt
- args:
- - init
- - bash
- - "--cmd"
- - wt
- env:
- CLICOLOR_FORCE: "1"
- COLUMNS: "150"
- GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
- 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/.tmpMCL1XL/test-config.toml
----
-success: true
-exit_code: 0
------ stdout -----
-# worktrunk shell integration for bash
-
-# Only initialize if wt is available
-if command -v wt >/dev/null 2>&1; then
- # Use WORKTRUNK_BIN if set, otherwise default to 'wt'
- # This allows testing development builds: export WORKTRUNK_BIN=./target/debug/wt
- _WORKTRUNK_CMD="${WORKTRUNK_BIN:-wt}"
-
- # Helper function to parse wt output and handle directives
- # Directives are NUL-terminated to support multi-line commands
- _wt_exec() {
- local exec_cmd="" chunk exit_code
- local exit_code_file
- exit_code_file=$(mktemp) || { echo "Failed to create temp file" >&2; return 1; }
-
- # Parse stdout for directives (NUL-delimited)
- # Let stderr pass through to terminal (preserves TTY for color detection)
- # Write exit code to temp file since it can't be captured from process substitution
- # The || [[ -n "$chunk" ]] handles non-NUL-terminated output (e.g., error messages)
- while IFS= read -r -d '' chunk || [[ -n "$chunk" ]]; do
- if [[ "$chunk" == __WORKTRUNK_CD__* ]]; then
- # CD directive - extract path and change directory
- local path="${chunk#__WORKTRUNK_CD__}"
- \cd "$path"
- elif [[ "$chunk" == __WORKTRUNK_EXEC__* ]]; then
- # EXEC directive - extract command (may contain newlines)
- exec_cmd="${chunk#__WORKTRUNK_EXEC__}"
- else
- # Regular output - print it with newline
- printf '%s\n' "$chunk"
- fi
- done < <(command "$_WORKTRUNK_CMD" "$@"; echo "$?" > "$exit_code_file")
-
- # Read exit code from temp file
- exit_code=$(cat "$exit_code_file" 2>/dev/null || echo 0)
-
- # Cleanup temp file
- \rm -f "$exit_code_file"
-
- # Execute command if one was specified
- # Security: Command is user-provided from -x flag; eval is intentional.
- # NUL-termination allows multi-line commands.
- # Exit code semantics: Returns wt's exit code, not the executed command's.
- # This allows detecting wt failures (e.g., branch creation errors).
- # The executed command runs for side effects; its failure is logged but doesn't affect exit code.
- if [[ -n "$exec_cmd" ]]; then
- if ! eval "$exec_cmd"; then
- echo "Warning: Command execution failed (exit code $?)" >&2
- fi
- fi
-
- return $exit_code
- }
-
- # Override wt command to add --internal flag for switch, remove, and merge
- wt() {
- local use_dev=false
- local args=()
- local saved_cmd="$_WORKTRUNK_CMD"
-
- # Check for --dev flag and strip it
- for arg in "$@"; do
- if [[ "$arg" == "--dev" ]]; then
- use_dev=true
- else
- args+=("$arg")
- fi
- done
-
- # If --dev was specified, build and use local debug binary
- if [[ "$use_dev" == true ]]; then
- if ! cargo build --quiet >/dev/null 2>&1; then
- echo "Error: cargo build failed" >&2
- _WORKTRUNK_CMD="$saved_cmd"
- return 1
- fi
- _WORKTRUNK_CMD="./target/debug/wt"
- fi
-
- # Dispatch based on subcommand
- if [[ ${#args[@]} -gt 0 ]]; then
- local subcommand="${args[0]}"
-
- case "$subcommand" in
- switch|remove|merge)
- # Commands that need --internal for directory change support
- _wt_exec --internal "${args[@]}"
- ;;
- *)
- # All other commands pass through directly
- command "$_WORKTRUNK_CMD" "${args[@]}"
- ;;
- esac
- else
- # No arguments, just run the command
- command "$_WORKTRUNK_CMD"
- fi
-
- # Restore original command
- local result=$?
- _WORKTRUNK_CMD="$saved_cmd"
- return $result
- }
-
- # Dynamic completion function
- _wt_complete() {
- local cur="${COMP_WORDS[COMP_CWORD]}"
-
- # Call wt complete with current command line
- local completions=$(command "$_WORKTRUNK_CMD" complete "${COMP_WORDS[@]}" 2>/dev/null)
- COMPREPLY=($(compgen -W "$completions" -- "$cur"))
- }
-
- # Register dynamic completion
- complete -F _wt_complete wt
-fi
-
-# Static completions (commands and flags)
-_wt() {
- local i cur prev opts cmd
- COMPREPLY=()
- if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
- cur="$2"
- else
- cur="${COMP_WORDS[COMP_CWORD]}"
- fi
- prev="$3"
- cmd=""
- opts=""
-
- for i in "${COMP_WORDS[@]:0:COMP_CWORD}"
- do
- case "${cmd},${i}" in
- ",$1")
- cmd="wt"
- ;;
- wt,complete)
- cmd="wt__complete"
- ;;
- wt,completion)
- cmd="wt__completion"
- ;;
- wt,config)
- cmd="wt__config"
- ;;
- wt,configure-shell)
- cmd="wt__configure__shell"
- ;;
- wt,dev)
- cmd="wt__dev"
- ;;
- wt,init)
- cmd="wt__init"
- ;;
- wt,list)
- cmd="wt__list"
- ;;
- wt,merge)
- cmd="wt__merge"
- ;;
- wt,push)
- cmd="wt__push"
- ;;
- wt,remove)
- cmd="wt__remove"
- ;;
- wt,switch)
- cmd="wt__switch"
- ;;
- wt__config,help)
- cmd="wt__config__help"
- ;;
- wt__config,init)
- cmd="wt__config__init"
- ;;
- wt__config,list)
- cmd="wt__config__list"
- ;;
- wt__dev,run-hook)
- cmd="wt__dev__run__hook"
- ;;
- *)
- ;;
- esac
- done
-
- case "${cmd}" in
- wt)
- opts="-v -h -V --verbose --help --version init configure-shell config dev list switch remove push merge completion complete"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
- wt__complete)
- opts="-v -h --verbose --help [ARGS]..."
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
- wt__completion)
- opts="-v -h --verbose --help bash elvish fish nushell oil powershell xonsh zsh"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
- wt__config)
- opts="-v -h --verbose --help init list help"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
- wt__config__help)
- opts="-v -h --verbose --help"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
- wt__config__init)
- opts="-v -h --verbose --help"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
- wt__config__list)
- opts="-v -h --verbose --help"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
- wt__configure__shell)
- opts="-y -v -h --shell --cmd --yes --verbose --help"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- --shell)
- COMPREPLY=($(compgen -W "bash elvish fish nushell oil powershell xonsh zsh" -- "${cur}"))
- return 0
- ;;
- --cmd)
- COMPREPLY=($(compgen -f "${cur}"))
- return 0
- ;;
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
- wt__dev)
- opts="-v -h --verbose --help run-hook"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
- wt__dev__run__hook)
- opts="-f -v -h --force --verbose --help post-create post-start pre-commit pre-squash pre-merge post-merge"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
- wt__init)
- opts="-v -h --cmd --verbose --help bash elvish fish nushell oil powershell xonsh zsh"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- --cmd)
- COMPREPLY=($(compgen -f "${cur}"))
- return 0
- ;;
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
- wt__list)
- opts="-v -h --format --branches --verbose --help"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- --format)
- COMPREPLY=($(compgen -W "table json" -- "${cur}"))
- return 0
- ;;
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
- wt__merge)
- opts="-s -k -f -v -h --squash --keep --no-hooks --force --verbose --help [TARGET]"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
- wt__push)
- opts="-v -h --allow-merge-commits --verbose --help [TARGET]"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
- wt__remove)
- opts="-v -h --verbose --help [WORKTREES]..."
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
- wt__switch)
- opts="-c -b -x -f -v -h --create --base --execute --force --no-hooks --verbose --help <BRANCH>"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- --base)
- COMPREPLY=($(compgen -f "${cur}"))
- return 0
- ;;
- -b)
- COMPREPLY=($(compgen -f "${cur}"))
- return 0
- ;;
- --execute)
- COMPREPLY=($(compgen -f "${cur}"))
- return 0
- ;;
- -x)
- COMPREPLY=($(compgen -f "${cur}"))
- return 0
- ;;
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
- esac
-}
-
-if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
- complete -F _wt -o nosort -o bashdefault -o default wt
-else
- complete -F _wt -o bashdefault -o default wt
-fi
-
------ stderr -----
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap b/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap
new file mode 100644
index 000000000..43c850adf
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__merge__merge_no_remote.snap
@@ -0,0 +1,25 @@
+---
+source: tests/integration_tests/merge.rs
+info:
+ program: wt
+ args:
+ - merge
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ 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/.tmpVOl1iS/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+✅ Already on feature, nothing to merge
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__push__push_no_remote.snap b/tests/snapshots/integration__integration_tests__push__push_no_remote.snap
new file mode 100644
index 000000000..5b3060d22
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__push__push_no_remote.snap
@@ -0,0 +1,25 @@
+---
+source: tests/integration_tests/push.rs
+info:
+ program: wt
+ args:
+ - push
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ 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/.tmpjaOCrN/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+✅ Pushed to feature
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_create_no_remote.snap b/tests/snapshots/integration__integration_tests__switch__switch_create_no_remote.snap
new file mode 100644
index 000000000..becaf2544
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_create_no_remote.snap
@@ -0,0 +1,29 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--create"
+ - feature
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ 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/.tmpYSLsbM/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+✅ Created new worktree for feature at [REPO].feature
+
+To enable automatic cd, run: wt config shell
+
+----- stderr -----