diff --git a/assets/chezmoi.io/docs/reference/commands/init.md b/assets/chezmoi.io/docs/reference/commands/init.md index 64837b2c4db..880193028c7 100644 --- a/assets/chezmoi.io/docs/reference/commands/init.md +++ b/assets/chezmoi.io/docs/reference/commands/init.md @@ -57,6 +57,10 @@ existing template data. Clone the repo with depth *depth*. +### `--git-lfs` *bool* + +Run `git lfs pull` after cloning the repo. + ### `-g`, `--guess-repo-url` *bool* Guess the repo URL from the *repo* argument. This defaults to `true`. 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 84c870aa4be..7f20f7e76c1 100644 --- a/assets/chezmoi.io/docs/reference/configuration-file/variables.md.yaml +++ b/assets/chezmoi.io/docs/reference/configuration-file/variables.md.yaml @@ -226,6 +226,9 @@ sections: commitMessageTemplateFile: type: string description: Commit message template file (relative to source directory) + lfs: + type: bool + description: Run `git lfs pull` after cloning gitHub: refreshPeriod: type: duration diff --git a/internal/cmd/gitcmd.go b/internal/cmd/gitcmd.go index 64ff4cc2156..091ec6b7b5e 100644 --- a/internal/cmd/gitcmd.go +++ b/internal/cmd/gitcmd.go @@ -11,6 +11,7 @@ type gitCmdConfig struct { AutoPush bool `json:"autopush" mapstructure:"autopush" yaml:"autopush"` CommitMessageTemplate string `json:"commitMessageTemplate" mapstructure:"commitMessageTemplate" yaml:"commitMessageTemplate"` CommitMessageTemplateFile string `json:"commitMessageTemplateFile" mapstructure:"commitMessageTemplateFile" yaml:"commitMessageTemplateFile"` + LFS bool `json:"lfs" mapstructure:"lfs" yaml:"lfs"` } func (c *Config) newGitCmd() *cobra.Command { diff --git a/internal/cmd/initcmd.go b/internal/cmd/initcmd.go index 22c5d4c3ed5..eba3ba670d9 100644 --- a/internal/cmd/initcmd.go +++ b/internal/cmd/initcmd.go @@ -110,6 +110,7 @@ func (c *Config) newInitCmd() *cobra.Command { initCmd.Flags().VarP(c.init.filter.Exclude, "exclude", "x", "Exclude entry types") initCmd.Flags().BoolVarP(&c.init.guessRepoURL, "guess-repo-url", "g", c.init.guessRepoURL, "Guess the repo URL") initCmd.Flags().VarP(c.init.filter.Include, "include", "i", "Include entry types") + initCmd.Flags().BoolVar(&c.Git.LFS, "git-lfs", c.Git.LFS, "Run git pull lfs after cloning") initCmd.Flags().BoolVar(&c.init.oneShot, "one-shot", c.init.oneShot, "Run in one-shot mode") initCmd.Flags().BoolVarP(&c.init.purge, "purge", "p", c.init.purge, "Purge config and source directories after running") initCmd.Flags().BoolVarP(&c.init.purgeBinary, "purge-binary", "P", c.init.purgeBinary, "Purge chezmoi binary after running") @@ -129,6 +130,8 @@ func (c *Config) runInitCmd(cmd *cobra.Command, args []string) error { c.init.purgeBinary = true } + useBuiltinGit := c.UseBuiltinGit.Value(c.useBuiltinGitAutoFunc) + // If we're not in a working tree then init it or clone it. gitDirAbsPath := c.WorkingTreeAbsPath.JoinString(git.GitDirName) switch _, err := c.baseSystem.Stat(gitDirAbsPath); { @@ -138,8 +141,6 @@ func (c *Config) runInitCmd(cmd *cobra.Command, args []string) error { return err } - useBuiltinGit := c.UseBuiltinGit.Value(c.useBuiltinGitAutoFunc) - if len(args) == 0 { if useBuiltinGit { if err := c.builtinGitInit(workingTreeRawPath); err != nil { @@ -196,6 +197,13 @@ func (c *Config) runInitCmd(cmd *cobra.Command, args []string) error { return err } + if c.Git.LFS && !useBuiltinGit { + args := []string{"lfs", "pull"} + if err := c.run(chezmoi.EmptyAbsPath, c.Git.Command, args); err != nil { + return err + } + } + // Apply. if c.init.apply { if err := c.applyArgs(cmd.Context(), c.destSystem, c.DestDirAbsPath, noArgs, applyArgsOptions{ diff --git a/internal/cmd/testdata/scripts/initgitlfs.txtar b/internal/cmd/testdata/scripts/initgitlfs.txtar new file mode 100644 index 00000000000..518e4328289 --- /dev/null +++ b/internal/cmd/testdata/scripts/initgitlfs.txtar @@ -0,0 +1,15 @@ +[windows] skip 'UNIX only' + +chmod 755 bin/git + +# test that chezmoi init --git-lfs runs git lfs pull after cloning +exec chezmoi init --git-lfs user +cmpenv stdout golden/init + +-- bin/git -- +#!/bin/sh + +echo git $* +-- golden/init -- +git clone --recurse-submodules https://github.com/user/dotfiles.git $HOME/.local/share/chezmoi +git lfs pull