Skip to content

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

test: add switch nonexistent-branch test, reference #977 (#979)

Maximilian Roos32a53027f9b1
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index a08054421..baedcc1c4 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -261,7 +261,7 @@ fn test_switch_base_without_create_warning(repo: TestRepo) {
#[rstest]
fn test_switch_create_with_invalid_base(repo: TestRepo) {
- // Issue #562: Error message should identify the invalid base branch,
+ // Issues #562, #977: Error message should identify the invalid base branch,
// not the target branch being created
snapshot_switch(
"switch_create_invalid_base",
@@ -270,6 +270,13 @@ fn test_switch_create_with_invalid_base(repo: TestRepo) {
);
}
+#[rstest]
+fn test_switch_nonexistent_branch(repo: TestRepo) {
+ // Switching to a nonexistent branch (without --create) should give a clear
+ // "branch not found" error, not fall through to a confusing git error.
+ snapshot_switch("switch_nonexistent_branch", &repo, &["nonexistent-branch"]);
+}
+
#[rstest]
fn test_switch_base_accepts_commitish(repo: TestRepo) {
// Issue #630: --base should accept any commit-ish, not just branch names
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_branch.snap b/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_branch.snap
new file mode 100644
index 000000000..8110d8f10
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_nonexistent_branch.snap
@@ -0,0 +1,42 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - nonexistent-branch
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WT_TEST_DELAYED_STREAM_MS: "-1"
+ WT_TEST_EPOCH: "1735776000"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+✗ No branch named nonexistent-branch
+↳ To create a new branch, run wt switch nonexistent-branch --create; to list branches, run wt list --branches --remotes