-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Change init to default to --config if --config-path is absent
Fixes #3127.
- Loading branch information
Showing
10 changed files
with
215 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
[windows] skip 'test requires path separator to be forward slash' | ||
# test the init command with 3 different sets of --config/--config-format options | ||
|
||
|
||
#### test chezmoi init | ||
|
||
chhome home1/user | ||
mkdir $CHEZMOISOURCEDIR | ||
|
||
# test that chezmoi init writes the initial config into the defaul config dir | ||
cp golden/chezmoi1.yaml $CHEZMOISOURCEDIR/.chezmoi.yaml.tmpl | ||
exec chezmoi init | ||
cmp $CHEZMOICONFIGDIR/chezmoi.yaml golden/chezmoi1.yaml | ||
|
||
# test that chezmoi init writes an updated config into the defaul config dir | ||
cp golden/chezmoi2.yaml $CHEZMOISOURCEDIR/.chezmoi.yaml.tmpl | ||
exec chezmoi init | ||
cmp $CHEZMOICONFIGDIR/chezmoi.yaml golden/chezmoi2.yaml | ||
|
||
# test that chezmoi init writes a config of a new format into the defaul config dir | ||
rm $CHEZMOISOURCEDIR/.chezmoi.yaml.tmpl | ||
cp golden/chezmoi3.toml $CHEZMOISOURCEDIR/.chezmoi.toml.tmpl | ||
exec chezmoi init | ||
cmp $CHEZMOICONFIGDIR/chezmoi.yaml golden/chezmoi2.yaml | ||
cmp $CHEZMOICONFIGDIR/chezmoi.toml golden/chezmoi3.toml | ||
|
||
# check that the last operation broke chezmoi | ||
! exec chezmoi status | ||
! stdout . | ||
cmpenv stderr golden/error1.log | ||
|
||
# check that deleting the old config file fixes the issue | ||
rm $CHEZMOICONFIGDIR/chezmoi.yaml | ||
exec chezmoi status | ||
! stdout . | ||
! stderr . | ||
|
||
# check that the state file was written into the default config dir | ||
exists $CHEZMOICONFIGDIR/chezmoistate.boltdb | ||
|
||
|
||
#### test chezmoi --config=path init | ||
|
||
chhome home2/user | ||
mkdir $CHEZMOISOURCEDIR | ||
|
||
# test that chezmoi --config=path init writes the initial config into path | ||
cp golden/chezmoi1.yaml $CHEZMOISOURCEDIR/.chezmoi.yaml.tmpl | ||
exec chezmoi --config=$HOME/.chezmoi/athome.yaml init | ||
cmp $HOME/.chezmoi/athome.yaml golden/chezmoi1.yaml | ||
|
||
# test that chezmoi --config=path init writes an updated config into path | ||
cp golden/chezmoi2.yaml $CHEZMOISOURCEDIR/.chezmoi.yaml.tmpl | ||
exec chezmoi --config=$HOME/.chezmoi/athome.yaml init | ||
cmp $HOME/.chezmoi/athome.yaml golden/chezmoi2.yaml | ||
|
||
# test that chezmoi --config=path init writes a config of a new format into path | ||
rm $CHEZMOISOURCEDIR/.chezmoi.yaml.tmpl | ||
cp golden/chezmoi3.toml $CHEZMOISOURCEDIR/.chezmoi.toml.tmpl | ||
exec chezmoi --config=$HOME/.chezmoi/athome.yaml init | ||
cmp $HOME/.chezmoi/athome.yaml golden/chezmoi3.toml | ||
|
||
# check that the last operation broke chezmoi | ||
! exec chezmoi --config=$HOME/.chezmoi/athome.yaml status | ||
! stdout . | ||
cmpenv stderr golden/error2.log | ||
|
||
# check that renaming the file and updating the config path fixes the issue | ||
mv $HOME/.chezmoi/athome.yaml $HOME/.chezmoi/athome.toml | ||
exec chezmoi --config=$HOME/.chezmoi/athome.toml status | ||
! stdout . | ||
! stderr . | ||
|
||
# check that the state file was written next to the config file | ||
exists $HOME/.chezmoi/chezmoistate.boltdb | ||
|
||
# check that nothing was ever written into the default config dir | ||
! exists $CHEZMOICONFIGDIR/chezmoi.toml | ||
! exists $CHEZMOICONFIGDIR/chezmoistate.boltdb | ||
|
||
|
||
#### test chezmoi --config=path --config-format=format init | ||
|
||
chhome home3/user | ||
mkdir $CHEZMOISOURCEDIR | ||
|
||
# test that chezmoi --config=path --config-format=format init writes the initial config into path | ||
cp golden/chezmoi1.yaml $CHEZMOISOURCEDIR/.chezmoi.yaml.tmpl | ||
exec chezmoi --config=$HOME/.chezmoi/athome.txt --config-format=yaml init | ||
cmp $HOME/.chezmoi/athome.txt golden/chezmoi1.yaml | ||
|
||
# test that chezmoi --config=path --config-format=format init writes an updated config into path | ||
cp golden/chezmoi2.yaml $CHEZMOISOURCEDIR/.chezmoi.yaml.tmpl | ||
exec chezmoi --config=$HOME/.chezmoi/athome.txt --config-format=yaml init | ||
cmp $HOME/.chezmoi/athome.txt golden/chezmoi2.yaml | ||
|
||
# test that chezmoi --config=path --config-format=format init writes a config of a new format into path | ||
rm $CHEZMOISOURCEDIR/.chezmoi.yaml.tmpl | ||
cp golden/chezmoi3.toml $CHEZMOISOURCEDIR/.chezmoi.toml.tmpl | ||
exec chezmoi --config=$HOME/.chezmoi/athome.txt --config-format=yaml init | ||
cmp $HOME/.chezmoi/athome.txt golden/chezmoi3.toml | ||
|
||
# check that the last operation broke chezmoi | ||
! exec chezmoi --config=$HOME/.chezmoi/athome.txt --config-format=yaml status | ||
! stdout . | ||
cmpenv stderr golden/error3.log | ||
|
||
# check that updating the config format fixes the issue | ||
exec chezmoi --config=$HOME/.chezmoi/athome.txt --config-format=toml status | ||
! stdout . | ||
! stderr . | ||
|
||
# check that the state file was written next to the config file | ||
exists $HOME/.chezmoi/chezmoistate.boltdb | ||
|
||
# check that nothing was ever written into the default config dir | ||
! exists $CHEZMOICONFIGDIR/chezmoi.toml | ||
! exists $CHEZMOICONFIGDIR/chezmoistate.boltdb | ||
|
||
|
||
-- golden/chezmoi1.yaml -- | ||
data: | ||
email: "[email protected]" | ||
-- golden/chezmoi2.yaml -- | ||
data: | ||
email: "[email protected]" | ||
-- golden/chezmoi3.toml -- | ||
[data] | ||
email = "[email protected]" | ||
-- golden/error1.log -- | ||
chezmoi: multiple config files: $CHEZMOICONFIGDIR/chezmoi.toml and $CHEZMOICONFIGDIR/chezmoi.yaml | ||
-- golden/error2.log -- | ||
chezmoi: invalid config: $HOME/.chezmoi/athome.yaml: yaml: unmarshal errors: line 1: cannot unmarshal !!seq into map[string]interface {} | ||
-- golden/error3.log -- | ||
chezmoi: invalid config: $HOME/.chezmoi/athome.txt: yaml: unmarshal errors: line 1: cannot unmarshal !!seq into map[string]interface {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
mkdir $CHEZMOISOURCEDIR | ||
|
||
# test that chezmoi --config=path init --config-path=path writes the initial config into path | ||
cp golden/config1.toml $CHEZMOISOURCEDIR/.chezmoi.toml.tmpl | ||
exec chezmoi --config=$HOME/config/athome.toml init --config-path=$HOME/config/athome.toml | ||
cmp $HOME/config/athome.toml golden/config1.toml | ||
|
||
# test that chezmoi --config=path init --config-path=path writes an updated config into path | ||
cp golden/config2.toml $CHEZMOISOURCEDIR/.chezmoi.toml.tmpl | ||
exec chezmoi --config=$HOME/config/athome.toml init --config-path=$HOME/config/athome.toml | ||
cmp $HOME/config/athome.toml golden/config2.toml | ||
|
||
# test that chezmoi --config=path init writes an updated config into path | ||
cp golden/config3.toml $CHEZMOISOURCEDIR/.chezmoi.toml.tmpl | ||
exec chezmoi --config=$HOME/config/athome.toml init | ||
cmp $HOME/config/athome.toml golden/config3.toml | ||
|
||
|
||
-- golden/config1.toml -- | ||
[data] | ||
email = "[email protected]" | ||
-- golden/config2.toml -- | ||
[data] | ||
email = "[email protected]" | ||
-- golden/config3.toml -- | ||
[data] | ||
email = "[email protected]" |