Skip to content

Commit

Permalink
[RELEASE STABLE] cmd/get: Refactor git clone.
Browse files Browse the repository at this point in the history
Properly clone the default branch of given git url,
instead of assuming 'main' as the default branch.

Signed-off-by: Divya Antony J.R <[email protected]>
antony-jr committed Nov 5, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 974c9b7 commit 5b54a44
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions internal/cmd/get/get.go
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 5b54a44

Please sign in to comment.