Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit63fe230

Browse files
fix: detect nested dotfiles scripts (#14455)
1 parent47f2c7d commit63fe230

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

‎cli/dotfiles.go‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7-
"io/fs"
87
"os"
98
"os/exec"
109
"path/filepath"
@@ -184,7 +183,7 @@ func (r *RootCmd) dotfiles() *serpent.Command {
184183
}
185184
}
186185

187-
script:=findScript(installScriptSet,files)
186+
script:=findScript(installScriptSet,dotfilesDir)
188187
ifscript!="" {
189188
_,err=cliui.Prompt(inv, cliui.PromptOptions{
190189
Text:fmt.Sprintf("Running install script %s.\n\n Continue?",script),
@@ -361,15 +360,12 @@ func dirExists(name string) (bool, error) {
361360
}
362361

363362
// findScript will find the first file that matches the script set.
364-
funcfindScript(scriptSet []string,files []fs.DirEntry)string {
363+
funcfindScript(scriptSet []string,directorystring)string {
365364
for_,i:=rangescriptSet {
366-
for_,f:=rangefiles {
367-
iff.Name()==i {
368-
returnf.Name()
369-
}
365+
if_,err:=os.Stat(filepath.Join(directory,i));err==nil {
366+
returni
370367
}
371368
}
372-
373369
return""
374370
}
375371

‎cli/dotfiles_test.go‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,41 @@ func TestDotfiles(t *testing.T) {
142142
require.NoError(t,err)
143143
require.Equal(t,string(b),"wow\n")
144144
})
145+
146+
t.Run("NestedInstallScript",func(t*testing.T) {
147+
t.Parallel()
148+
ifruntime.GOOS=="windows" {
149+
t.Skip("install scripts on windows require sh and aren't very practical")
150+
}
151+
_,root:=clitest.New(t)
152+
testRepo:=testGitRepo(t,root)
153+
154+
scriptPath:=filepath.Join("script","setup")
155+
err:=os.MkdirAll(filepath.Join(testRepo,"script"),0o750)
156+
require.NoError(t,err)
157+
// nolint:gosec
158+
err=os.WriteFile(filepath.Join(testRepo,scriptPath), []byte("#!/bin/bash\necho wow > "+filepath.Join(string(root),".bashrc")),0o750)
159+
require.NoError(t,err)
160+
161+
c:=exec.Command("git","add",scriptPath)
162+
c.Dir=testRepo
163+
err=c.Run()
164+
require.NoError(t,err)
165+
166+
c=exec.Command("git","commit","-m",`"add script"`)
167+
c.Dir=testRepo
168+
err=c.Run()
169+
require.NoError(t,err)
170+
171+
inv,_:=clitest.New(t,"dotfiles","--global-config",string(root),"--symlink-dir",string(root),"-y",testRepo)
172+
err=inv.Run()
173+
require.NoError(t,err)
174+
175+
b,err:=os.ReadFile(filepath.Join(string(root),".bashrc"))
176+
require.NoError(t,err)
177+
require.Equal(t,string(b),"wow\n")
178+
})
179+
145180
t.Run("InstallScriptChangeBranch",func(t*testing.T) {
146181
t.Parallel()
147182
ifruntime.GOOS=="windows" {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp