Skip to content

Commit 7d513f3

Browse files
committed
Don't run scripts in diff mode
1 parent 1e70622 commit 7d513f3

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

cmd/diff.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func init() {
2020
}
2121

2222
func (c *Config) runDiffCmd(fs vfs.FS, args []string) error {
23+
c.DryRun = true
2324
mutator := chezmoi.NewLoggingMutator(c.Stdout(), chezmoi.NullMutator{}, c.colored)
2425
return c.applyArgs(fs, args, mutator)
2526
}

cmd/diff_posix_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// +build !windows
2+
3+
package cmd
4+
5+
import (
6+
"io/ioutil"
7+
"os"
8+
"path/filepath"
9+
"testing"
10+
11+
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/require"
13+
vfs "github.com/twpayne/go-vfs"
14+
"github.com/twpayne/go-vfs/vfst"
15+
)
16+
17+
func TestDiffDoesNotRunScript(t *testing.T) {
18+
tempDir, err := ioutil.TempDir("", "chezmoi")
19+
require.NoError(t, err)
20+
defer func() {
21+
require.NoError(t, os.RemoveAll(tempDir))
22+
}()
23+
fs := vfs.NewPathFS(vfs.OSFS, tempDir)
24+
require.NoError(t, vfst.NewBuilder().Build(
25+
fs,
26+
map[string]interface{}{
27+
"/home/user/.local/share/chezmoi/run_true": "#!/bin/sh\necho foo >>" + filepath.Join(tempDir, "evidence") + "\n",
28+
},
29+
))
30+
c := &Config{
31+
SourceDir: "/home/user/.local/share/chezmoi",
32+
DestDir: "/",
33+
Umask: 022,
34+
}
35+
assert.NoError(t, c.runDiffCmd(fs, nil))
36+
vfst.RunTests(t, vfs.OSFS, "",
37+
vfst.TestPath(filepath.Join(tempDir, "evidence"),
38+
vfst.TestDoesNotExist,
39+
),
40+
)
41+
}

0 commit comments

Comments
 (0)