diff --git a/assets/chezmoi.io/docs/reference/commands/update.md b/assets/chezmoi.io/docs/reference/commands/update.md index 56b06ed0bef..9377603143c 100644 --- a/assets/chezmoi.io/docs/reference/commands/update.md +++ b/assets/chezmoi.io/docs/reference/commands/update.md @@ -6,6 +6,10 @@ Pull changes from the source repo and apply any changes. Only update entries of type *types*. +## `--recurse-submodules` *bool* + +Update submodules recursively. This defaults to `true`. + !!! example ```console diff --git a/assets/chezmoi.io/docs/reference/configuration-file/variables.md.yaml b/assets/chezmoi.io/docs/reference/configuration-file/variables.md.yaml index f47e364ab34..65431da5a08 100644 --- a/assets/chezmoi.io/docs/reference/configuration-file/variables.md.yaml +++ b/assets/chezmoi.io/docs/reference/configuration-file/variables.md.yaml @@ -266,6 +266,11 @@ sections: command: default: "`vault`" description: "Vault CLI command" + update: + recurseSubmodules: + type: "bool" + default: "`true`" + description: "Update submodules recursively" verify: exclude: type: "[]string" diff --git a/pkg/cmd/config.go b/pkg/cmd/config.go index 0fb71b29d9b..b5790dddad2 100644 --- a/pkg/cmd/config.go +++ b/pkg/cmd/config.go @@ -126,6 +126,7 @@ type ConfigFile struct { Git gitCmdConfig `mapstructure:"git"` Merge mergeCmdConfig `mapstructure:"merge"` Status statusCmdConfig `mapstructure:"status"` + Update updateCmdConfig `mapstructure:"update"` Verify verifyCmdConfig `mapstructure:"verify"` } @@ -167,7 +168,6 @@ type Config struct { remove removeCmdConfig secret secretCmdConfig state stateCmdConfig - update updateCmdConfig upgrade upgradeCmdConfig // Version information. @@ -315,11 +315,6 @@ func newConfig(options ...configOption) (*Config, error) { reAdd: reAddCmdConfig{ filter: chezmoi.NewEntryTypeFilter(chezmoi.EntryTypesAll, chezmoi.EntryTypesNone), }, - update: updateCmdConfig{ - apply: true, - filter: chezmoi.NewEntryTypeFilter(chezmoi.EntryTypesAll, chezmoi.EntryTypesNone), - recursive: true, - }, upgrade: upgradeCmdConfig{ owner: gitHubOwner, repo: gitHubRepo, @@ -2409,6 +2404,12 @@ func newConfigFile(bds *xdg.BaseDirectorySpecification) ConfigFile { include: chezmoi.NewEntryTypeSet(chezmoi.EntryTypesAll), recursive: true, }, + Update: updateCmdConfig{ + RecurseSubmodules: true, + apply: true, + filter: chezmoi.NewEntryTypeFilter(chezmoi.EntryTypesAll, chezmoi.EntryTypesNone), + recursive: true, + }, Verify: verifyCmdConfig{ Exclude: chezmoi.NewEntryTypeSet(chezmoi.EntryTypesNone), include: chezmoi.NewEntryTypeSet(chezmoi.EntryTypesAll), diff --git a/pkg/cmd/updatecmd.go b/pkg/cmd/updatecmd.go index 6406677b903..66ebf00b0ea 100644 --- a/pkg/cmd/updatecmd.go +++ b/pkg/cmd/updatecmd.go @@ -10,10 +10,11 @@ import ( ) type updateCmdConfig struct { - apply bool - filter *chezmoi.EntryTypeFilter - init bool - recursive bool + RecurseSubmodules bool + apply bool + filter *chezmoi.EntryTypeFilter + init bool + recursive bool } func (c *Config) newUpdateCmd() *cobra.Command { @@ -34,11 +35,12 @@ func (c *Config) newUpdateCmd() *cobra.Command { } flags := updateCmd.Flags() - flags.BoolVarP(&c.update.apply, "apply", "a", c.update.apply, "Apply after pulling") - flags.VarP(c.update.filter.Exclude, "exclude", "x", "Exclude entry types") - flags.VarP(c.update.filter.Include, "include", "i", "Include entry types") - flags.BoolVar(&c.update.init, "init", c.update.init, "Recreate config file from template") - flags.BoolVarP(&c.update.recursive, "recursive", "r", c.update.recursive, "Recurse into subdirectories") + flags.BoolVarP(&c.Update.apply, "apply", "a", c.Update.apply, "Apply after pulling") + flags.VarP(c.Update.filter.Exclude, "exclude", "x", "Exclude entry types") + flags.VarP(c.Update.filter.Include, "include", "i", "Include entry types") + flags.BoolVar(&c.Update.init, "init", c.Update.init, "Recreate config file from template") + flags.BoolVar(&c.Update.RecurseSubmodules, "recurse-submodules", c.Update.RecurseSubmodules, "Recursively update submodules") //nolint:lll + flags.BoolVarP(&c.Update.recursive, "recursive", "r", c.Update.recursive, "Recurse into subdirectories") registerExcludeIncludeFlagCompletionFuncs(updateCmd) @@ -69,18 +71,22 @@ func (c *Config) runUpdateCmd(cmd *cobra.Command, args []string) error { "pull", "--autostash", "--rebase", - "--recurse-submodules", + } + if c.Update.RecurseSubmodules { + args = append(args, + "--recurse-submodules", + ) } if err := c.run(c.WorkingTreeAbsPath, c.Git.Command, args); err != nil { return err } } - if c.update.apply { + if c.Update.apply { if err := c.applyArgs(cmd.Context(), c.destSystem, c.DestDirAbsPath, args, applyArgsOptions{ - filter: c.update.filter, - init: c.update.init, - recursive: c.update.recursive, + filter: c.Update.filter, + init: c.Update.init, + recursive: c.Update.recursive, umask: c.Umask, preApplyFunc: c.defaultPreApplyFunc, }); err != nil {