From 6cbea26f7f5b12bb296ab27a2bb7b0a6946affe9 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Thu, 1 Apr 2021 16:50:05 -0700 Subject: [PATCH] cmd/plan/git: allow for optional ref (default to HEAD) Signed-off-by: Sam Alba --- cmd/dagger/cmd/input/git.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/dagger/cmd/input/git.go b/cmd/dagger/cmd/input/git.go index b3afc73a..64cc92eb 100644 --- a/cmd/dagger/cmd/input/git.go +++ b/cmd/dagger/cmd/input/git.go @@ -8,9 +8,9 @@ import ( ) var gitCmd = &cobra.Command{ - Use: "git TARGET REMOTE REF [SUBDIR]", + Use: "git TARGET REMOTE [REF] [SUBDIR]", Short: "Add a git repository as input artifact", - Args: cobra.RangeArgs(3, 4), + Args: cobra.RangeArgs(2, 4), PreRun: func(cmd *cobra.Command, args []string) { // Fix Viper bug for duplicate flags: // https://github.com/spf13/viper/issues/233 @@ -22,12 +22,17 @@ var gitCmd = &cobra.Command{ lg := logger.New() ctx := lg.WithContext(cmd.Context()) + ref := "HEAD" + if len(args) > 2 { + ref = args[2] + } + subDir := "" if len(args) > 3 { subDir = args[3] } - updateDeploymentInput(ctx, args[0], dagger.GitInput(args[1], args[2], subDir)) + updateDeploymentInput(ctx, args[0], dagger.GitInput(args[1], ref, subDir)) }, }