Skip to content

Commit eecf015

Browse files
committedOct 8, 2023
fix: Only invoke diff pager if command modifies filesystem
1 parent 3fa83c1 commit eecf015

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed
 

‎internal/cmd/config.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,9 @@ func (c *Config) persistentPreRunRootE(cmd *cobra.Command, args []string) error
19921992
c.sourceSystem = chezmoi.NewDryRunSystem(c.sourceSystem)
19931993
c.destSystem = chezmoi.NewDryRunSystem(c.destSystem)
19941994
}
1995-
if c.Verbose || annotations.hasTag(outputsDiff) {
1995+
if annotations.hasTag(outputsDiff) ||
1996+
c.Verbose &&
1997+
(annotations.hasTag(modifiesDestinationDirectory) || annotations.hasTag(modifiesSourceDirectory)) {
19961998
// If the user has configured a diff pager, then start it as a process.
19971999
// Otherwise, write the diff output directly to stdout.
19982000
var writer io.Writer

‎internal/cmd/statuscmd.go

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func (c *Config) newStatusCmd() *cobra.Command {
2828
RunE: c.runStatusCmd,
2929
Annotations: newAnnotations(
3030
dryRun,
31-
modifiesDestinationDirectory,
3231
persistentStateModeReadMockWrite,
3332
requiresSourceDirectory,
3433
),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[windows] skip 'UNIX only'
2+
3+
chmod 755 bin/custom-pager
4+
5+
# test that chezmoi add invokes the pager when verbose is set
6+
exec chezmoi add $HOME${/}.file
7+
stdout custom-pager
8+
9+
# test chat chezmoi chattr invokes the pager when verbose is set
10+
exec chezmoi chattr +private $HOME${/}.file
11+
stdout custom-pager
12+
13+
# test that chezmoi status does not invoke the pager when verbose is set
14+
exec chezmoi status
15+
! stdout custom-pager
16+
17+
-- bin/custom-pager --
18+
#!/bin/sh
19+
20+
echo custom-pager
21+
-- home/user/.config/chezmoi/chezmoi.yaml --
22+
pager: custom-pager
23+
verbose: true
24+
-- home/user/.file --
25+
# contents of .file
26+
-- home/user/.local/share/chezmoi/.keep --

0 commit comments

Comments
 (0)
Please sign in to comment.