Last active
February 25, 2022 08:29
-
-
Save arehmandev/38869d6fcce7b7e3871d7e5d4ac98e27 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