diff --git a/pkg/cmd/sourcepathcmd.go b/pkg/cmd/sourcepathcmd.go index 3edc594594f..4ed13e35abb 100644 --- a/pkg/cmd/sourcepathcmd.go +++ b/pkg/cmd/sourcepathcmd.go @@ -5,8 +5,6 @@ import ( "strings" "github.com/spf13/cobra" - - "github.com/twpayne/chezmoi/v2/pkg/chezmoi" ) func (c *Config) newSourcePathCmd() *cobra.Command { @@ -16,17 +14,22 @@ func (c *Config) newSourcePathCmd() *cobra.Command { Long: mustLongHelp("source-path"), Example: example("source-path"), ValidArgsFunction: c.targetValidArgs, - RunE: c.makeRunEWithSourceState(c.runSourcePathCmd), + RunE: c.runSourcePathCmd, } return sourcePathCmd } -func (c *Config) runSourcePathCmd(cmd *cobra.Command, args []string, sourceState *chezmoi.SourceState) error { +func (c *Config) runSourcePathCmd(cmd *cobra.Command, args []string) error { if len(args) == 0 { return c.writeOutputString(c.SourceDirAbsPath.String() + "\n") } + sourceState, err := c.newSourceState(cmd.Context()) + if err != nil { + return err + } + sourceAbsPaths, err := c.sourceAbsPaths(sourceState, args) if err != nil { return err diff --git a/pkg/cmd/testdata/scripts/issue2354.txtar b/pkg/cmd/testdata/scripts/issue2354.txtar new file mode 100644 index 00000000000..c9ae77c44d5 --- /dev/null +++ b/pkg/cmd/testdata/scripts/issue2354.txtar @@ -0,0 +1,6 @@ +# test that chezmoi source-path does not read the source state if not needed +exec chezmoi source-path +stdout ${CHEZMOISOURCEDIR@R} + +-- home/user/.local/share/chezmoi/.chezmoiexternal.json -- +invalid JSON file