Skip to content

Commit

Permalink
fix: Include git repo external state in state dump output
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Oct 24, 2022
1 parent 90a5ce5 commit d30c50c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
26 changes: 16 additions & 10 deletions pkg/chezmoi/persistentstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ var (
// EntryStateBucket is the bucket for recording the entry states.
EntryStateBucket = []byte("entryState")

// gitRepoExternalState is the bucket for recording the state of commands
// that modify directories.
gitRepoExternalState = []byte("gitRepoExternalState")

// scriptStateBucket is the bucket for recording the state of run once
// scripts.
scriptStateBucket = []byte("scriptState")

// modifyDirWithCmdStateBucket is the bucket for recording the state of
// commands that modify directories.
modifyDirWithCmdStateBucket = []byte("gitRepoExternalState")

stateFormat = formatJSON{}
)

Expand Down Expand Up @@ -56,18 +56,24 @@ func PersistentStateData(s PersistentState) (any, error) {
if err != nil {
return nil, err
}
gitRepoExternalData, err := PersistentStateBucketData(s, gitRepoExternalState)
if err != nil {
return nil, err
}
scriptStateData, err := PersistentStateBucketData(s, scriptStateBucket)
if err != nil {
return nil, err
}
return struct {
ConfigState any `json:"configState" yaml:"configState"`
EntryState any `json:"entryState" yaml:"entryState"`
ScriptState any `json:"scriptState" yaml:"scriptState"`
ConfigState any `json:"configState" yaml:"configState"`
EntryState any `json:"entryState" yaml:"entryState"`
GitRepoExternalData any `json:"gitRepoExternalState" yaml:"gitRepoExternalState"`
ScriptState any `json:"scriptState" yaml:"scriptState"`
}{
ConfigState: configStateData,
EntryState: entryStateData,
ScriptState: scriptStateData,
ConfigState: configStateData,
EntryState: entryStateData,
GitRepoExternalData: gitRepoExternalData,
ScriptState: scriptStateData,
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/chezmoi/targetstateentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (t *TargetStateModifyDirWithCmd) Apply(

modifyDirWithCmdStateKey := []byte(actualStateEntry.Path().String())
if err := persistentStateSet(
persistentState, modifyDirWithCmdStateBucket, modifyDirWithCmdStateKey, &modifyDirWithCmdState{
persistentState, gitRepoExternalState, modifyDirWithCmdStateKey, &modifyDirWithCmdState{
Name: actualStateEntry.Path(),
RunAt: runAt,
}); err != nil {
Expand Down Expand Up @@ -119,7 +119,7 @@ func (t *TargetStateModifyDirWithCmd) SkipApply(persistentState PersistentState,
return false, nil
}
modifyDirWithCmdKey := []byte(targetAbsPath.String())
switch modifyDirWithCmdStateBytes, err := persistentState.Get(modifyDirWithCmdStateBucket, modifyDirWithCmdKey); {
switch modifyDirWithCmdStateBytes, err := persistentState.Get(gitRepoExternalState, modifyDirWithCmdKey); {
case err != nil:
return false, err
case modifyDirWithCmdStateBytes == nil:
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/testdata/scripts/configstate.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ configState:
configState:
configTemplateContentsSHA256: af43121a524340707b84e390f510c949731177e6f2a25b3b6b11b2fc656cf8f2
entryState: {}
gitRepoExternalState: {}
scriptState: {}
-- home/user/.local/share/chezmoi/.chezmoi.toml.tmpl --
[data]
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/testdata/scripts/state_unix.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ stdout runAt:
-- golden/dump.yaml --
configState: {}
entryState: {}
gitRepoExternalState: {}
scriptState: {}
-- home/user/.local/share/chezmoi/run_once_script.sh --
#!/bin/sh
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/testdata/scripts/state_windows.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ exec chezmoi --force state reset
-- golden/dump.yaml --
configState: {}
entryState: {}
gitRepoExternalState: {}
scriptState: {}
-- home/user/.local/share/chezmoi/run_once_script.cmd --
:: don't need to actually do anything

0 comments on commit d30c50c

Please sign in to comment.