Skip to content

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

test: verify worktrunk works with worktree.useRelativePaths (#1631)

worktrunk-bot240abe282a15
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index 4524202d4..eed5195e3 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -3386,6 +3386,53 @@ fn test_switch_no_cd_flag_explicit(repo: TestRepo) {
);
}
+/// Test that worktrunk works correctly when `worktree.useRelativePaths` is enabled.
+///
+/// Git 2.48+ supports `worktree.useRelativePaths`, which stores relative paths in the
+/// `.git` file of linked worktrees instead of absolute paths. This makes worktree
+/// directories relocatable. We verify that worktrunk's path handling (which canonicalizes
+/// paths internally) works correctly with this configuration.
+///
+/// See: https://github.com/max-sixty/worktrunk/issues/1630
+#[rstest]
+fn test_switch_with_relative_worktree_paths(repo: TestRepo) {
+ // Enable relative paths for worktrees
+ repo.run_git(&["config", "worktree.useRelativePaths", "true"]);
+
+ // Create a new worktree via wt switch --create
+ snapshot_switch(
+ "switch_create_relative_paths",
+ &repo,
+ &["--create", "relative-test"],
+ );
+
+ // Verify the .git file in the worktree contains a relative path
+ let worktree_path = repo
+ .root_path()
+ .parent()
+ .unwrap()
+ .join("repo.relative-test");
+ let git_file = std::fs::read_to_string(worktree_path.join(".git")).unwrap();
+ assert!(
+ !git_file.contains(repo.root_path().to_str().unwrap()),
+ "Expected relative path in .git file, but found absolute path: {git_file}"
+ );
+ assert!(
+ git_file.contains("gitdir: ../"),
+ "Expected relative gitdir in .git file: {git_file}"
+ );
+
+ // Verify wt list shows the worktree (path resolution works)
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "list", &[], None);
+ assert_cmd_snapshot!("list_with_relative_paths", cmd);
+ });
+
+ // Verify switching to the relative-path worktree works
+ snapshot_switch("switch_to_relative_paths", &repo, &["relative-test"]);
+}
+
/// Test that `[switch] no-cd = true` config is respected when no flags provided
#[rstest]
fn test_switch_no_cd_config_default(repo: TestRepo) {
diff --git a/tests/snapshots/integration__integration_tests__switch__list_with_relative_paths.snap b/tests/snapshots/integration__integration_tests__switch__list_with_relative_paths.snap
new file mode 100644
index 000000000..da24a9db4
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__list_with_relative_paths.snap
@@ -0,0 +1,51 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - list
+ 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]"
+ NO_COLOR: ""
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+ Branch Status HEAD± main↕ Remote⇅ Path Commit Age Message
+@ main ^| | . 05a4a45d 16h Initial commit
++ feature-a ↑ ↑1 ../repo.feature-a 1b87d473 16h Add feature-a file
++ feature-b ↑ ↑1 ../repo.feature-b f62940fc 16h Add feature-b file
++ feature-c ↑ ↑1 ../repo.feature-c 345c7c93 16h Add feature-c file
++ relative-test _ ../repo.relative-test 05a4a45d 16h Initial commit
+
+○ Showing 5 worktrees, 3 ahead
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_create_relative_paths.snap b/tests/snapshots/integration__integration_tests__switch__switch_create_relative_paths.snap
new file mode 100644
index 000000000..adba77bbf
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_create_relative_paths.snap
@@ -0,0 +1,49 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "--create"
+ - relative-test
+ 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]"
+ NO_COLOR: ""
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✓ Created branch relative-test from main and worktree @ _REPO_.relative-test
+↳ To customize worktree locations, run wt config create
+▲ Cannot change directory — shell integration not installed
+↳ To enable automatic cd, run wt config shell install
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_to_relative_paths.snap b/tests/snapshots/integration__integration_tests__switch__switch_to_relative_paths.snap
new file mode 100644
index 000000000..b2025216e
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_to_relative_paths.snap
@@ -0,0 +1,46 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - relative-test
+ 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]"
+ NO_COLOR: ""
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+▲ Worktree for relative-test @ _REPO_.relative-test, but cannot change directory — shell integration not installed
+↳ To enable automatic cd, run wt config shell install