From 7fc3c38ca333247bf9fd4a903f6b5b055bd2a0a4 Mon Sep 17 00:00:00 2001 From: Omer Zidkoni <50792403+omerzi@users.noreply.github.com> Date: Wed, 21 Dec 2022 13:18:08 +0200 Subject: [PATCH] Skip CreateDotGitFolderWithRemote if .git exists (#57) --- vcsutils/utils.go | 4 ++++ vcsutils/utils_test.go | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/vcsutils/utils.go b/vcsutils/utils.go index 5dc7c69c..2277f593 100644 --- a/vcsutils/utils.go +++ b/vcsutils/utils.go @@ -271,6 +271,10 @@ func generateErrorString(bodyArray []byte) string { // CreateDotGitFolderWithRemote creates a .git folder inside path with remote details of remoteName and remoteUrl func CreateDotGitFolderWithRemote(path, remoteName, remoteUrl string) error { repo, err := git.PlainInit(path, false) + if err == git.ErrRepositoryAlreadyExists { + // If the .git folder already exists, we can skip this function + return nil + } if err != nil { return err } diff --git a/vcsutils/utils_test.go b/vcsutils/utils_test.go index a219e609..fd466080 100644 --- a/vcsutils/utils_test.go +++ b/vcsutils/utils_test.go @@ -181,8 +181,8 @@ func TestCreateDotGitFolderWithRemote(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, remote) assert.Contains(t, remote.Config().URLs, "fakeurl") - // Return error if .git already exist - assert.Error(t, CreateDotGitFolderWithRemote(dir1, "origin", "fakeurl")) + // Return no err if .git already exist + assert.NoError(t, CreateDotGitFolderWithRemote(dir1, "origin", "fakeurl")) } func TestCreateDotGitFolderWithoutRemote(t *testing.T) {