diff --git a/docs.md b/docs.md index e5c2619..266e5d6 100644 --- a/docs.md +++ b/docs.md @@ -47,6 +47,7 @@ clone: | `tags` | `false` (except on tag event) | Fetches tags when set to true, default is false if event is not tag else true | | `submodule_overrides` | _none_ | Override submodule urls | | `submodule_update_remote` | `false` | Pass the --remote flag to git submodule update | +| `submodule_partial` | `true` | Update submodules via partial clone (depth=1) | | `custom_ssl_path` | _none_ | Set path to custom cert | | `custom_ssl_url` | _none_ | Set url to custom cert | | `backoff` | `5sec` | Change backoff duration | diff --git a/flags.go b/flags.go index 0de3506..234a93b 100644 --- a/flags.go +++ b/flags.go @@ -91,6 +91,12 @@ var globalFlags = []cli.Flag{ EnvVars: []string{"PLUGIN_SUBMODULE_OVERRIDE"}, Value: &MapFlag{}, }, + &cli.BoolFlag{ + Name: "submodule-partial", + Usage: "update submodules via partial clone (depth=1) (default)", + EnvVars: []string{"PLUGIN_SUBMODULES_PARTIAL", "PLUGIN_SUBMODULE_PARTIAL"}, + Value: true, + }, &cli.DurationFlag{ Name: "backoff", Usage: "backoff duration", diff --git a/main.go b/main.go index 8d93c41..c33d6f8 100644 --- a/main.go +++ b/main.go @@ -45,20 +45,21 @@ func run(c *cli.Context) error { Password: c.String("netrc.password"), }, Config: Config{ - Depth: c.Int("depth"), - Tags: c.Bool("tags"), - Recursive: c.Bool("recursive"), - SkipVerify: c.Bool("skip-verify"), - CustomCert: c.String("custom-cert"), - SubmoduleRemote: c.Bool("submodule-update-remote"), - Submodules: c.Generic("submodule-override").(*MapFlag).Get(), - Lfs: c.Bool("lfs"), - Branch: c.String("branch"), - Partial: c.Bool("partial"), - Home: c.String("home"), - SafeDirectory: c.String("safe-directory"), - UseSSH: c.Bool("use-ssh"), - SSHKey: c.String("ssh-key"), + Depth: c.Int("depth"), + Tags: c.Bool("tags"), + Recursive: c.Bool("recursive"), + SkipVerify: c.Bool("skip-verify"), + CustomCert: c.String("custom-cert"), + SubmoduleRemote: c.Bool("submodule-update-remote"), + Submodules: c.Generic("submodule-override").(*MapFlag).Get(), + SubmodulePartial: c.Bool("submodule-partial"), + Lfs: c.Bool("lfs"), + Branch: c.String("branch"), + Partial: c.Bool("partial"), + Home: c.String("home"), + SafeDirectory: c.String("safe-directory"), + UseSSH: c.Bool("use-ssh"), + SSHKey: c.String("ssh-key"), }, Backoff: Backoff{ Attempts: c.Int("backoff-attempts"), diff --git a/plugin.go b/plugin.go index 226ff41..0664c51 100644 --- a/plugin.go +++ b/plugin.go @@ -92,7 +92,7 @@ func (p Plugin) Exec() error { } if p.Config.Recursive { - cmds = append(cmds, updateSubmodules(p.Config.SubmoduleRemote)) + cmds = append(cmds, updateSubmodules(p.Config.SubmoduleRemote, p.Config.SubmodulePartial)) } if p.Config.Lfs { @@ -295,14 +295,12 @@ func fetch(ref string, tags bool, depth int, filter string) *exec.Cmd { } // updateSubmodules recursively initializes and updates submodules. -func updateSubmodules(remote bool) *exec.Cmd { - cmd := exec.Command( - "git", - "submodule", - "update", - "--init", - "--recursive", - ) +func updateSubmodules(remote, partial bool) *exec.Cmd { + args := []string{"submodule", "update", "--init", "--recursive"} + if partial { + args = append(args, "--depth=1", "--recommend-shallow") + } + cmd := exec.Command("git", args...) if remote { cmd.Args = append(cmd.Args, "--remote") diff --git a/plugin_test.go b/plugin_test.go index c0f9427..c86a297 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -278,11 +278,11 @@ func TestFetch(t *testing.T) { // are constructed properly. func TestUpdateSubmodules(t *testing.T) { testdata := []struct { - depth int - exp []string + partial bool + exp []string }{ { - 50, + false, []string{ "git", "submodule", @@ -292,18 +292,20 @@ func TestUpdateSubmodules(t *testing.T) { }, }, { - 100, + true, []string{ "git", "submodule", "update", "--init", "--recursive", + "--depth=1", + "--recommend-shallow", }, }, } for _, td := range testdata { - c := updateSubmodules(false) + c := updateSubmodules(false, td.partial) if len(c.Args) != len(td.exp) { t.Errorf("Expected: %s, got %s", td.exp, c.Args) } @@ -374,11 +376,9 @@ func TestCustomCertFile(t *testing.T) { // are constructed properly. func TestUpdateSubmodulesRemote(t *testing.T) { testdata := []struct { - depth int - exp []string + exp []string }{ { - 50, []string{ "git", "submodule", @@ -389,7 +389,6 @@ func TestUpdateSubmodulesRemote(t *testing.T) { }, }, { - 100, []string{ "git", "submodule", @@ -401,7 +400,7 @@ func TestUpdateSubmodulesRemote(t *testing.T) { }, } for _, td := range testdata { - c := updateSubmodules(true) + c := updateSubmodules(true, false) if len(c.Args) != len(td.exp) { t.Errorf("Expected: %s, got %s", td.exp, c.Args) } diff --git a/types.go b/types.go index 8833994..61719cc 100644 --- a/types.go +++ b/types.go @@ -26,21 +26,22 @@ type ( } Config struct { - Depth int - Recursive bool - SkipVerify bool - Tags bool - Submodules map[string]string - SubmoduleRemote bool - CustomCert string - Lfs bool - Branch string - Home string - Partial bool - filter string - SafeDirectory string - UseSSH bool - SSHKey string + Depth int + Recursive bool + SkipVerify bool + Tags bool + Submodules map[string]string + SubmoduleRemote bool + SubmodulePartial bool + CustomCert string + Lfs bool + Branch string + Home string + Partial bool + filter string + SafeDirectory string + UseSSH bool + SSHKey string } Backoff struct {