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.rsindex 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.snapnew file mode 100644index 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 -----+ [1mBranch[0m [1mStatus[0m [1mHEAD±[0m [1mmain↕[0m [1mRemote⇅[0m [1mPath[0m [1mCommit[0m [1mAge[0m [1mMessage+@ main [2m^[22m[2m|[22m [2m|[0m . [2m05a4a45d[0m [2m16h[0m [2mInitial commit++ feature-a [2m↑[22m [32m↑1[0m ../repo.feature-a [2m1b87d473[0m [2m16h[0m [2mAdd feature-a file++ feature-b [2m↑[22m [32m↑1[0m ../repo.feature-b [2mf62940fc[0m [2m16h[0m [2mAdd feature-b file++ feature-c [2m↑[22m [32m↑1[0m ../repo.feature-c [2m345c7c93[0m [2m16h[0m [2mAdd feature-c file++ [2mrelative-test[0m [2m_[22m [2m../repo.relative-test[0m [2m05a4a45d[0m [2m16h[0m [2mInitial commit++[2m○[22m [2mShowing 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.snapnew file mode 100644index 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 -----+[32m✓[39m [32mCreated branch [1mrelative-test[22m from [1mmain[22m and worktree @ [1m_REPO_.relative-test[22m[39m+[2m↳[22m [2mTo customize worktree locations, run [4mwt config create[24m[22m+[33m▲[39m [33mCannot change directory — shell integration not installed[39m+[2m↳[22m [2mTo enable automatic cd, run [4mwt config shell install[24m[22mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_to_relative_paths.snap b/tests/snapshots/integration__integration_tests__switch__switch_to_relative_paths.snapnew file mode 100644index 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 -----+[33m▲[39m [33mWorktree for [1mrelative-test[22m @ [1m_REPO_.relative-test[22m, but cannot change directory — shell integration not installed[39m+[2m↳[22m [2mTo enable automatic cd, run [4mwt config shell install[24m[22m