From a25f10f24765b3ce464cf28059239fa4a299dcde Mon Sep 17 00:00:00 2001 From: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com> Date: Tue, 14 Nov 2023 23:27:58 +0100 Subject: [PATCH] Add `--tag` and `--branch` options to bundle init command (#975) ## Tests Tested manually. Specified branch / tag are indeed cloned and used by bundle init. --- cmd/bundle/init.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cmd/bundle/init.go b/cmd/bundle/init.go index cd2af420..ccdc6859 100644 --- a/cmd/bundle/init.go +++ b/cmd/bundle/init.go @@ -60,14 +60,27 @@ See https://docs.databricks.com/en/dev-tools/bundles/templates.html for more inf var configFile string var outputDir string var templateDir string + var tag string + var branch string cmd.Flags().StringVar(&configFile, "config-file", "", "File containing input parameters for template initialization.") cmd.Flags().StringVar(&templateDir, "template-dir", "", "Directory path within a Git repository containing the template.") cmd.Flags().StringVar(&outputDir, "output-dir", "", "Directory to write the initialized template to.") + cmd.Flags().StringVar(&branch, "tag", "", "Git tag to use for template initialization") + cmd.Flags().StringVar(&tag, "branch", "", "Git branch to use for template initialization") cmd.PreRunE = root.MustWorkspaceClient cmd.RunE = func(cmd *cobra.Command, args []string) error { - ctx := cmd.Context() + if tag != "" && branch != "" { + return errors.New("only one of --tag or --branch can be specified") + } + // Git ref to use for template initialization + ref := branch + if tag != "" { + ref = tag + } + + ctx := cmd.Context() var templatePath string if len(args) > 0 { templatePath = args[0] @@ -104,7 +117,7 @@ See https://docs.databricks.com/en/dev-tools/bundles/templates.html for more inf } // TODO: Add automated test that the downloaded git repo is cleaned up. // Clone the repository in the temporary directory - err = git.Clone(ctx, templatePath, "", repoDir) + err = git.Clone(ctx, templatePath, ref, repoDir) if err != nil { return err }