diff --git a/pkg/cmd/sourcepathcmd.go b/pkg/cmd/sourcepathcmd.go index 4ed13e35abb..ca82a21dcf3 100644 --- a/pkg/cmd/sourcepathcmd.go +++ b/pkg/cmd/sourcepathcmd.go @@ -22,7 +22,11 @@ func (c *Config) newSourcePathCmd() *cobra.Command { func (c *Config) runSourcePathCmd(cmd *cobra.Command, args []string) error { if len(args) == 0 { - return c.writeOutputString(c.SourceDirAbsPath.String() + "\n") + sourceDirAbsPath, err := c.sourceDirAbsPath() + if err != nil { + return err + } + return c.writeOutputString(sourceDirAbsPath.String() + "\n") } sourceState, err := c.newSourceState(cmd.Context()) diff --git a/pkg/cmd/testdata/scripts/issue2380.txt b/pkg/cmd/testdata/scripts/issue2380.txt new file mode 100644 index 00000000000..b42d14d2cc7 --- /dev/null +++ b/pkg/cmd/testdata/scripts/issue2380.txt @@ -0,0 +1,6 @@ +# test that chezmoi source-path with no arguments respects .chezmoiroot +exec chezmoi source-path +stdout ${CHEZMOISOURCEDIR@R}/home + +-- home/user/.local/share/chezmoi/.chezmoiroot -- +home