Skip to content

Commit

Permalink
feat: Add --recurse-submodules flag to update command
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Oct 29, 2022
1 parent 1ccde54 commit 081b58c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
4 changes: 4 additions & 0 deletions assets/chezmoi.io/docs/reference/commands/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 7 additions & 6 deletions pkg/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -167,7 +168,6 @@ type Config struct {
remove removeCmdConfig
secret secretCmdConfig
state stateCmdConfig
update updateCmdConfig
upgrade upgradeCmdConfig

// Version information.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
34 changes: 20 additions & 14 deletions pkg/cmd/updatecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 081b58c

Please sign in to comment.