Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add test for skipping re-adding a modified external #4366

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions internal/cmd/catconfigcmd.go
Original file line number Diff line number Diff line change
@@ -4,12 +4,13 @@ import "github.com/spf13/cobra"

func (c *Config) newCatConfigCmd() *cobra.Command {
catConfigCmd := &cobra.Command{
Use: "cat-config",
Short: "Print the configuration file",
Long: mustLongHelp("cat-config"),
Example: example("cat-config"),
Args: cobra.NoArgs,
RunE: c.runCatConfigCmd,
Use: "cat-config",
Short: "Print the configuration file",
Long: mustLongHelp("cat-config"),
Example: example("cat-config"),
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: c.runCatConfigCmd,
Annotations: newAnnotations(
doesNotRequireValidConfig,
persistentStateModeReadOnly,
2 changes: 2 additions & 0 deletions internal/cmd/config.go
Original file line number Diff line number Diff line change
@@ -1760,9 +1760,11 @@ func (c *Config) newRootCmd() (*cobra.Command, error) {
rootCmd.RegisterFlagCompletionFunc("color", autoBoolFlagCompletionFunc),
rootCmd.RegisterFlagCompletionFunc("config-format", c.configFormat.FlagCompletionFunc()),
rootCmd.RegisterFlagCompletionFunc("mode", chezmoi.ModeFlagCompletionFunc),
rootCmd.RegisterFlagCompletionFunc("progress", autoBoolFlagCompletionFunc),
rootCmd.RegisterFlagCompletionFunc("refresh-externals", chezmoi.RefreshExternalsFlagCompletionFunc),
rootCmd.RegisterFlagCompletionFunc("use-builtin-age", autoBoolFlagCompletionFunc),
rootCmd.RegisterFlagCompletionFunc("use-builtin-git", autoBoolFlagCompletionFunc),
rootCmd.MarkPersistentFlagDirname("working-tree"),
); err != nil {
return nil, err
}
13 changes: 7 additions & 6 deletions internal/cmd/datacmd.go
Original file line number Diff line number Diff line change
@@ -14,12 +14,13 @@ type dataCmdConfig struct {

func (c *Config) newDataCmd() *cobra.Command {
dataCmd := &cobra.Command{
Use: "data",
Short: "Print the template data",
Long: mustLongHelp("data"),
Example: example("data"),
Args: cobra.NoArgs,
RunE: c.runDataCmd,
Use: "data",
Short: "Print the template data",
Long: mustLongHelp("data"),
Example: example("data"),
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: c.runDataCmd,
Annotations: newAnnotations(
persistentStateModeReadOnly,
),
13 changes: 7 additions & 6 deletions internal/cmd/doctorcmd.go
Original file line number Diff line number Diff line change
@@ -150,12 +150,13 @@ type doctorCmdConfig struct {

func (c *Config) newDoctorCmd() *cobra.Command {
doctorCmd := &cobra.Command{
Args: cobra.NoArgs,
Use: "doctor",
Short: "Check your system for potential problems",
Example: example("doctor"),
Long: mustLongHelp("doctor"),
RunE: c.runDoctorCmd,
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
Use: "doctor",
Short: "Check your system for potential problems",
Example: example("doctor"),
Long: mustLongHelp("doctor"),
RunE: c.runDoctorCmd,
Annotations: newAnnotations(
doesNotRequireValidConfig,
persistentStateModeNone,
13 changes: 7 additions & 6 deletions internal/cmd/dumpconfigcmd.go
Original file line number Diff line number Diff line change
@@ -12,12 +12,13 @@ type dumpConfigCmdConfig struct {

func (c *Config) newDumpConfigCmd() *cobra.Command {
dumpConfigCmd := &cobra.Command{
Use: "dump-config",
Short: "Dump the configuration values",
Long: mustLongHelp("dump-config"),
Example: example("dump-config"),
Args: cobra.NoArgs,
RunE: c.runDumpConfigCmd,
Use: "dump-config",
Short: "Dump the configuration values",
Long: mustLongHelp("dump-config"),
Example: example("dump-config"),
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: c.runDumpConfigCmd,
Annotations: newAnnotations(
persistentStateModeReadOnly,
),
13 changes: 7 additions & 6 deletions internal/cmd/editconfigcmd.go
Original file line number Diff line number Diff line change
@@ -6,12 +6,13 @@ import (

func (c *Config) newEditConfigCmd() *cobra.Command {
editConfigCmd := &cobra.Command{
Use: "edit-config",
Short: "Edit the configuration file",
Long: mustLongHelp("edit-config"),
Example: example("edit-config"),
Args: cobra.NoArgs,
RunE: c.runEditConfigCmd,
Use: "edit-config",
Short: "Edit the configuration file",
Long: mustLongHelp("edit-config"),
Example: example("edit-config"),
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: c.runEditConfigCmd,
Annotations: newAnnotations(
doesNotRequireValidConfig,
modifiesConfigFile,
13 changes: 7 additions & 6 deletions internal/cmd/editconfigtemplatecmd.go
Original file line number Diff line number Diff line change
@@ -11,12 +11,13 @@ import (

func (c *Config) newEditConfigTemplateCmd() *cobra.Command {
editConfigCmd := &cobra.Command{
Use: "edit-config-template",
Short: "Edit the configuration file template",
Long: mustLongHelp("edit-config-template"),
Example: example("edit-config-template"),
Args: cobra.NoArgs,
RunE: c.makeRunEWithSourceState(c.runEditConfigTemplateCmd),
Use: "edit-config-template",
Short: "Edit the configuration file template",
Long: mustLongHelp("edit-config-template"),
Example: example("edit-config-template"),
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: c.makeRunEWithSourceState(c.runEditConfigTemplateCmd),
Annotations: newAnnotations(
doesNotRequireValidConfig,
modifiesSourceDirectory,
11 changes: 6 additions & 5 deletions internal/cmd/helpcmd.go
Original file line number Diff line number Diff line change
@@ -9,11 +9,12 @@ import (

func (c *Config) newHelpCmd() *cobra.Command {
helpCmd := &cobra.Command{
Use: "help [command]",
Short: "Print help about a command",
Long: mustLongHelp("help"),
Example: example("help"),
RunE: c.runHelpCmd,
Use: "help [command]",
Short: "Print help about a command",
Long: mustLongHelp("help"),
Example: example("help"),
RunE: c.runHelpCmd,
ValidArgsFunction: cobra.NoFileCompletions,
Annotations: newAnnotations(
doesNotRequireValidConfig,
persistentStateModeNone,
13 changes: 7 additions & 6 deletions internal/cmd/ignoredcmd.go
Original file line number Diff line number Diff line change
@@ -13,12 +13,13 @@ type ignoredCmdConfig struct {

func (c *Config) newIgnoredCmd() *cobra.Command {
ignoredCmd := &cobra.Command{
Use: "ignored",
Short: "Print ignored targets",
Long: mustLongHelp("ignored"),
Example: example("ignored"),
Args: cobra.NoArgs,
RunE: c.makeRunEWithSourceState(c.runIgnoredCmd),
Use: "ignored",
Short: "Print ignored targets",
Long: mustLongHelp("ignored"),
Example: example("ignored"),
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: c.makeRunEWithSourceState(c.runIgnoredCmd),
Annotations: newAnnotations(
persistentStateModeReadMockWrite,
),
13 changes: 7 additions & 6 deletions internal/cmd/licensecmd.go
Original file line number Diff line number Diff line change
@@ -6,12 +6,13 @@ import (

func (c *Config) newLicenseCmd() *cobra.Command {
licenseCmd := &cobra.Command{
Use: "license",
Short: "Print license",
Long: mustLongHelp("license"),
Example: example("license"),
Args: cobra.NoArgs,
RunE: c.runLicenseCmd,
Use: "license",
Short: "Print license",
Long: mustLongHelp("license"),
Example: example("license"),
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: c.runLicenseCmd,
Annotations: newAnnotations(
doesNotRequireValidConfig,
persistentStateModeNone,
13 changes: 7 additions & 6 deletions internal/cmd/purgecmd.go
Original file line number Diff line number Diff line change
@@ -19,12 +19,13 @@ type purgeCmdConfig struct {

func (c *Config) newPurgeCmd() *cobra.Command {
purgeCmd := &cobra.Command{
Use: "purge",
Short: "Purge chezmoi's configuration and data",
Long: mustLongHelp("purge"),
Example: example("purge"),
Args: cobra.NoArgs,
RunE: c.runPurgeCmd,
Use: "purge",
Short: "Purge chezmoi's configuration and data",
Long: mustLongHelp("purge"),
Example: example("purge"),
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: c.runPurgeCmd,
Annotations: newAnnotations(
modifiesDestinationDirectory,
modifiesSourceDirectory,
22 changes: 22 additions & 0 deletions internal/cmd/testdata/scripts/issue4358.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
httpd www

exec chezmoi apply
cmp $HOME/.file golden/.file

# check that modifying an external file and then running chezmoi re-add does not result in an inconsistent state
edit $HOME/.file
! cmp $HOME/.file golden/.file
exec chezmoi --exclude=externals re-add
exec chezmoi status
cmp stdout golden/status

-- golden/.file --
# contents of .file
-- golden/status --
MM .file
-- home/user/.local/share/chezmoi/.chezmoiexternal.toml.tmpl --
[".file"]
type = "file"
url = "{{ env "HTTPD_URL" }}/.file"
-- www/.file --
# contents of .file
13 changes: 7 additions & 6 deletions internal/cmd/updatecmd.go
Original file line number Diff line number Diff line change
@@ -22,12 +22,13 @@ type updateCmdConfig struct {

func (c *Config) newUpdateCmd() *cobra.Command {
updateCmd := &cobra.Command{
Use: "update",
Short: "Pull and apply any changes",
Long: mustLongHelp("update"),
Example: example("update"),
Args: cobra.NoArgs,
RunE: c.runUpdateCmd,
Use: "update",
Short: "Pull and apply any changes",
Long: mustLongHelp("update"),
Example: example("update"),
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: c.runUpdateCmd,
Annotations: newAnnotations(
modifiesDestinationDirectory,
persistentStateModeReadWrite,
13 changes: 7 additions & 6 deletions internal/cmd/upgradecmd.go
Original file line number Diff line number Diff line change
@@ -49,12 +49,13 @@ type upgradeCmdConfig struct {

func (c *Config) newUpgradeCmd() *cobra.Command {
upgradeCmd := &cobra.Command{
Use: "upgrade",
Short: "Upgrade chezmoi to the latest released version",
Long: mustLongHelp("upgrade"),
Example: example("upgrade"),
Args: cobra.NoArgs,
RunE: c.runUpgradeCmd,
Use: "upgrade",
Short: "Upgrade chezmoi to the latest released version",
Long: mustLongHelp("upgrade"),
Example: example("upgrade"),
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: c.runUpgradeCmd,
Annotations: newAnnotations(
persistentStateModeNone,
runsCommands,