fix: detect nested dotfiles scripts (#14455)

This commit is contained in:
Ethan
2024-08-28 02:14:23 +10:00
committed by GitHub
parent 47f2c7d683
commit 63fe2305f8
2 changed files with 39 additions and 8 deletions
+35
View File
@@ -142,6 +142,41 @@ func TestDotfiles(t *testing.T) {
require.NoError(t, err)
require.Equal(t, string(b), "wow\n")
})
t.Run("NestedInstallScript", func(t *testing.T) {
t.Parallel()
if runtime.GOOS == "windows" {
t.Skip("install scripts on windows require sh and aren't very practical")
}
_, root := clitest.New(t)
testRepo := testGitRepo(t, root)
scriptPath := filepath.Join("script", "setup")
err := os.MkdirAll(filepath.Join(testRepo, "script"), 0o750)
require.NoError(t, err)
// nolint:gosec
err = os.WriteFile(filepath.Join(testRepo, scriptPath), []byte("#!/bin/bash\necho wow > "+filepath.Join(string(root), ".bashrc")), 0o750)
require.NoError(t, err)
c := exec.Command("git", "add", scriptPath)
c.Dir = testRepo
err = c.Run()
require.NoError(t, err)
c = exec.Command("git", "commit", "-m", `"add script"`)
c.Dir = testRepo
err = c.Run()
require.NoError(t, err)
inv, _ := clitest.New(t, "dotfiles", "--global-config", string(root), "--symlink-dir", string(root), "-y", testRepo)
err = inv.Run()
require.NoError(t, err)
b, err := os.ReadFile(filepath.Join(string(root), ".bashrc"))
require.NoError(t, err)
require.Equal(t, string(b), "wow\n")
})
t.Run("InstallScriptChangeBranch", func(t *testing.T) {
t.Parallel()
if runtime.GOOS == "windows" {