Files
lazygit/pkg/integration/tests/worktree/default_path_tilde.go
T
Stefan HallerandClaude Opus 4.8 7a67cea687 Expand a leading ~ in worktree paths to the home directory
Lazygit runs git directly rather than through a shell, so a literal "~"
reaches `git worktree add` unexpanded and git creates a directory named
"~" instead of using the home directory.

Expand the tilde ourselves, both for paths typed into the "Other"
location prompt and for the worktree.defaultPath config value.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-03 18:53:05 +02:00

52 lines
1.5 KiB
Go

package worktree
import (
"os"
"path/filepath"
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var DefaultPathTilde = NewIntegrationTest(NewIntegrationTestArgs{
Description: "A leading ~ in the worktree.defaultPath config is expanded to the home directory",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().Worktree.DefaultPath = "~/my-worktrees"
},
SetupRepo: func(shell *Shell) {
shell.NewBranch("mybranch")
shell.CreateFileAndAdd("README.md", "hello world")
shell.Commit("initial commit")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Branches().
Focus().
NavigateToLine(Contains("mybranch")).
Press(keys.Universal.NewWorktree).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("New worktree")).
Select(Contains("New branch and worktree from 'mybranch'")).
Confirm()
t.ExpectPopup().Prompt().
Title(Equals("New branch and worktree name")).
Type("newbranch").
Confirm()
// The default path's "~" is expanded to an absolute home-directory
// path; without expansion it would stay a literal "~" resolved
// against the repo, so the candidate would still contain a "~".
home, _ := os.UserHomeDir()
t.ExpectPopup().Menu().
Title(Equals("Worktree location")).
ContainsLines(
Contains(filepath.Join(home, "my-worktrees", "newbranch")).DoesNotContain("~"),
).
Cancel()
})
},
})