From 5b54a44a309009ec4e01f590971c06ce85d12766 Mon Sep 17 00:00:00 2001 From: antony-jr Date: Sun, 5 Nov 2023 13:22:03 +0530 Subject: [PATCH] [RELEASE STABLE] cmd/get: Refactor git clone. Properly clone the default branch of given git url, instead of assuming 'main' as the default branch. Signed-off-by: Divya Antony J.R --- internal/cmd/get/get.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/internal/cmd/get/get.go b/internal/cmd/get/get.go index 943a3e8..2f309c6 100644 --- a/internal/cmd/get/get.go +++ b/internal/cmd/get/get.go @@ -170,8 +170,11 @@ Local Recipe: // Parse the string git_url, git_branch := ParseGitRemoteString(recipe_src) + gitUrl = git_url + gitBranch = git_branch + if git_branch == "" { - git_branch = "main" + git_branch = "Default" } _ = tuiSpinnerMsg.StopMessage() @@ -186,15 +189,19 @@ Local Recipe: dir = uniqueTempDir remove = true usedGit = true - gitUrl = git_url - gitBranch = git_branch tuiSpinnerMsg.ShowMessage(fmt.Sprintf("Cloning Into %s...", dir)) - _, err = git.PlainClone(dir, false, &git.CloneOptions{ - URL: gitUrl, - ReferenceName: plumbing.NewBranchReferenceName(gitBranch), - }) + if gitBranch == "" { + _, err = git.PlainClone(dir, false, &git.CloneOptions{ + URL: gitUrl, + }) + } else { + _, err = git.PlainClone(dir, false, &git.CloneOptions{ + URL: gitUrl, + ReferenceName: plumbing.NewBranchReferenceName(gitBranch), + }) + } if err != nil { _ = os.RemoveAll(dir)