Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 6 additions & 1 deletion bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,12 @@ func (b *Bootstrap) defaultCheckoutPhase(ctx context.Context) error {
}
}

if err := b.shell.Run(ctx, "git", "submodule", "update", "--init", "--recursive", "--force"); err != nil {
args := []string{}
for _, config := range b.GitSubmoduleCloneConfig {
args = append(args, "-c", config)
}
args = append(args, []string{"submodule", "update", "--init", "--recursive", "--force"}...)
if err := b.shell.Run(ctx, "git", args...); err != nil {
return err
}

Expand Down
3 changes: 3 additions & 0 deletions bootstrap/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ type Config struct {
// Flags to pass to "git clean" command
GitCleanFlags string `env:"BUILDKITE_GIT_CLEAN_FLAGS"`

// Flags to pass to "git" when submodule init commands are invoked
GitSubmoduleCloneConfig []string `env:"BUILDKITE_GIT_SUBMODULE_CLONE_CONFIG" normalize:"list"`

// Whether or not to run the hooks/commands in a PTY
RunInPty bool

Expand Down
2 changes: 1 addition & 1 deletion bootstrap/integration/bootstrap_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func NewBootstrapTester() (*BootstrapTester, error) {

// Support testing experiments
if exp := experiments.Enabled(); len(exp) > 0 {
bt.Env = append(bt.Env, `BUILDKITE_AGENT_EXPERIMENT=`+strings.Join(exp, ","))
bt.Env = append(bt.Env, "BUILDKITE_AGENT_EXPERIMENT="+strings.Join(exp, ","))

if experiments.IsEnabled("git-mirrors") {
gitMirrorsDir, err := os.MkdirTemp("", "bootstrap-git-mirrors")
Expand Down
9 changes: 5 additions & 4 deletions bootstrap/integration/checkout_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func TestCheckingOutLocalGitProjectWithSubmodules(t *testing.T) {
}
defer submoduleRepo.Close()

out, err := tester.Repo.Execute("submodule", "add", submoduleRepo.Path)
out, err := tester.Repo.Execute("-c", "protocol.file.allow=always", "submodule", "add", submoduleRepo.Path)
if err != nil {
t.Fatalf("tester.Repo.Execute(submodule, add, %q) error = %v\nout = %s", submoduleRepo.Path, err, out)
}
Expand All @@ -217,6 +217,7 @@ func TestCheckingOutLocalGitProjectWithSubmodules(t *testing.T) {
"BUILDKITE_GIT_CLONE_FLAGS=-v",
"BUILDKITE_GIT_CLEAN_FLAGS=-fdq",
"BUILDKITE_GIT_FETCH_FLAGS=-v",
"BUILDKITE_GIT_SUBMODULE_CLONE_CONFIG=protocol.file.allow=always",
}

// Actually execute git commands, but with expectations
Expand All @@ -235,7 +236,7 @@ func TestCheckingOutLocalGitProjectWithSubmodules(t *testing.T) {
{"checkout", "-f", "FETCH_HEAD"},
{"submodule", "sync", "--recursive"},
{"config", "--file", ".gitmodules", "--null", "--get-regexp", "submodule\\..+\\.url"},
{"submodule", "update", "--init", "--recursive", "--force"},
{"-c", "protocol.file.allow=always", "submodule", "update", "--init", "--recursive", "--force"},
{"submodule", "foreach", "--recursive", "git reset --hard"},
{"clean", "-fdq"},
{"submodule", "foreach", "--recursive", "git clean -fdq"},
Expand All @@ -250,7 +251,7 @@ func TestCheckingOutLocalGitProjectWithSubmodules(t *testing.T) {
{"checkout", "-f", "FETCH_HEAD"},
{"submodule", "sync", "--recursive"},
{"config", "--file", ".gitmodules", "--null", "--get-regexp", "submodule\\..+\\.url"},
{"submodule", "update", "--init", "--recursive", "--force"},
{"-c", "protocol.file.allow=always", "submodule", "update", "--init", "--recursive", "--force"},
{"submodule", "foreach", "--recursive", "git reset --hard"},
{"clean", "-fdq"},
{"submodule", "foreach", "--recursive", "git clean -fdq"},
Expand Down Expand Up @@ -286,7 +287,7 @@ func TestCheckingOutLocalGitProjectWithSubmodulesDisabled(t *testing.T) {
}
defer submoduleRepo.Close()

out, err := tester.Repo.Execute("submodule", "add", submoduleRepo.Path)
out, err := tester.Repo.Execute("-c", "protocol.file.allow=always", "submodule", "add", submoduleRepo.Path)
if err != nil {
t.Fatalf("tester.Repo.Execute(submodule, add, %q) error = %v\nout = %s", submoduleRepo.Path, err, out)
}
Expand Down
8 changes: 8 additions & 0 deletions clicommand/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type BootstrapConfig struct {
GitMirrorsPath string `cli:"git-mirrors-path" normalize:"filepath"`
GitMirrorsLockTimeout int `cli:"git-mirrors-lock-timeout"`
GitMirrorsSkipUpdate bool `cli:"git-mirrors-skip-update"`
GitSubmoduleCloneConfig []string `cli:"git-submodule-clone-config"`
BinPath string `cli:"bin-path" normalize:"filepath"`
BuildPath string `cli:"build-path" normalize:"filepath"`
HooksPath string `cli:"hooks-path" normalize:"filepath"`
Expand Down Expand Up @@ -221,6 +222,12 @@ var BootstrapCommand = cli.Command{
Usage: "Flags to pass to \"git fetch\" command",
EnvVar: "BUILDKITE_GIT_FETCH_FLAGS",
},
cli.StringSliceFlag{
Name: "git-submodule-clone-config",
Value: &cli.StringSlice{},
Usage: "Config key=value for git submodule clone commands",
EnvVar: "BUILDKITE_GIT_SUBMODULE_CLONE_CONFIG",
},
cli.StringFlag{
Name: "git-mirrors-path",
Value: "",
Expand Down Expand Up @@ -411,6 +418,7 @@ var BootstrapCommand = cli.Command{
GitMirrorsPath: cfg.GitMirrorsPath,
GitMirrorsSkipUpdate: cfg.GitMirrorsSkipUpdate,
GitSubmodules: cfg.GitSubmodules,
GitSubmoduleCloneConfig: cfg.GitSubmoduleCloneConfig,
HooksPath: cfg.HooksPath,
JobID: cfg.JobID,
LocalHooksEnabled: cfg.LocalHooksEnabled,
Expand Down