From e6000db8c51db1c409d684d389475205902232cf Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Thu, 29 Jun 2023 19:08:02 +0200 Subject: [PATCH] added error for when CLI is not installed --- internal/git_clone_test.go | 1 - libs/git/clone.go | 3 +++ libs/git/clone_test.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 libs/git/clone_test.go diff --git a/internal/git_clone_test.go b/internal/git_clone_test.go index 32f5e0164..a4bf40e91 100644 --- a/internal/git_clone_test.go +++ b/internal/git_clone_test.go @@ -11,7 +11,6 @@ import ( "github.com/stretchr/testify/assert" ) -// TODO: add assertion for error if git CLI is not found func TestAccGitClonePublicRepository(t *testing.T) { t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV")) diff --git a/libs/git/clone.go b/libs/git/clone.go index f3e968978..b2cace6ac 100644 --- a/libs/git/clone.go +++ b/libs/git/clone.go @@ -96,6 +96,9 @@ func clonePrivate(ctx context.Context, opts CloneOptions) error { // start git clone err := cmd.Start() + if errors.Is(err, exec.ErrNotFound) { + return fmt.Errorf("please install git CLI to download private templates: %w", err) + } if err != nil { return err } diff --git a/libs/git/clone_test.go b/libs/git/clone_test.go new file mode 100644 index 000000000..f337ea4c6 --- /dev/null +++ b/libs/git/clone_test.go @@ -0,0 +1,30 @@ +package git + +import ( + "context" + "os" + "os/exec" + "testing" + + "github.com/databricks/cli/libs/cmdio" + "github.com/stretchr/testify/assert" +) + +func TestGitCloneCLINotFound(t *testing.T) { + // Set PATH to "", so git CLI cannot be found + t.Setenv("PATH", "") + + tmpDir := t.TempDir() + cmdIO := cmdio.NewIO("text", os.Stdin, os.Stdout, os.Stderr, "") + ctx := cmdio.InContext(context.Background(), cmdIO) + + err := Clone(ctx, CloneOptions{ + Provider: "github", + Organization: "databricks", + RepositoryName: "does-not-exist", + Reference: "main", + TargetDir: tmpDir, + }) + assert.ErrorIs(t, err, exec.ErrNotFound) + assert.ErrorContains(t, err, "please install git CLI to download private templates") +}