Skip to content

Commit

Permalink
Skip CreateDotGitFolderWithRemote if .git exists (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
omerzi committed Dec 21, 2022
1 parent 5c028ca commit 7fc3c38
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions vcsutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions vcsutils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7fc3c38

Please sign in to comment.