diff --git a/cmd/server.go b/cmd/server.go index f8f92c5cb..b2c9827a3 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -33,6 +33,12 @@ import ( "github.com/runatlantis/atlantis/server/logging" ) +// checkout strategies +const ( + CheckoutStrategyBranch = "branch" + CheckoutStrategyMerge = "merge" +) + // To add a new flag you must: // 1. Add a const with the flag name (in alphabetic order). // 2. Add a new field to server.UserConfig and set the mapstructure tag equal to the flag name. @@ -141,7 +147,7 @@ const ( DefaultADHostname = "dev.azure.com" DefaultAutoplanFileList = "**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl" DefaultAllowCommands = "version,plan,apply,unlock,approve_policies" - DefaultCheckoutStrategy = "branch" + DefaultCheckoutStrategy = CheckoutStrategyBranch DefaultCheckoutDepth = 0 DefaultBitbucketBaseURL = bitbucketcloud.BaseURL DefaultDataDir = "~/.atlantis" @@ -545,7 +551,7 @@ var boolFlags = map[string]boolFlag{ } var intFlags = map[string]intFlag{ CheckoutDepthFlag: { - description: fmt.Sprintf("Used only if --%s=merge.", CheckoutStrategyFlag) + + description: fmt.Sprintf("Used only if --%s=%s.", CheckoutStrategyFlag, CheckoutStrategyMerge) + " How many commits to include in each of base and feature branches when cloning repository." + " If merge base is further behind than this number of commits from any of branches heads, full fetch will be performed.", defaultValue: DefaultCheckoutDepth, @@ -852,8 +858,9 @@ func (s *ServerCmd) validate(userConfig server.UserConfig) error { } checkoutStrategy := userConfig.CheckoutStrategy - if checkoutStrategy != "branch" && checkoutStrategy != "merge" { - return errors.New("invalid checkout strategy: not one of branch or merge") + if checkoutStrategy != CheckoutStrategyBranch && checkoutStrategy != CheckoutStrategyMerge { + return fmt.Errorf("invalid checkout strategy: not one of %s or %s", + CheckoutStrategyBranch, CheckoutStrategyMerge) } if (userConfig.SSLKeyFile == "") != (userConfig.SSLCertFile == "") { diff --git a/cmd/server_test.go b/cmd/server_test.go index 0e518c636..c8d64ef09 100644 --- a/cmd/server_test.go +++ b/cmd/server_test.go @@ -66,7 +66,7 @@ var testFlags = map[string]interface{}{ BitbucketTokenFlag: "bitbucket-token", BitbucketUserFlag: "bitbucket-user", BitbucketWebhookSecretFlag: "bitbucket-secret", - CheckoutStrategyFlag: "merge", + CheckoutStrategyFlag: CheckoutStrategyMerge, DataDirFlag: "/path", DefaultTFVersionFlag: "v0.11.0", DisableApplyAllFlag: true,