-
-
Save roscopecoltran/84d00d5c5c9b50643220f92c43b4c536 to your computer and use it in GitHub Desktop.
Doing a git clone of a tag in Go - the easy way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"gopkg.in/src-d/go-git.v4/plumbing" | |
"gopkg.in/src-d/go-git.v4" | |
) | |
// Basic example of how to clone a repository using clone options. | |
func main() { | |
url := "https://github.com/arehmandev/pochelm.git" | |
directory := "pochelm" | |
tag := "v0.2.0" | |
gitclonetag(url, directory, tag) | |
} | |
func gitclonetag(repourl, directory, tag string) { | |
y := plumbing.ReferenceName(tag) | |
// Clone the given repository to the given directory, you can also clone branches via ReferenceName: "refs/heads/branchname" | |
_, err := git.PlainClone(directory, false, &git.CloneOptions{ | |
URL: repourl, | |
ReferenceName: "refs/tags/" + y, | |
SingleBranch: true, | |
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth, | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment