Add tag support

This commit is contained in:
d1slike committed 2024-05-31 20:14:06 +03:00
1 parent 7e9513f98b
commit bc5555706d
3 files changed
+15 -4

No files matched your search

+12 -3
View File
@@ -3,6 +3,7 @@ package command
import (
"io"
"os"
"regexp"
"github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-git/v5"
@@ -12,6 +13,10 @@ import (
"github.com/urfave/cli/v2"
)
var (
semverRegexp = regexp.MustCompile("v([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?$")
)
func GitGet() *cli.Command {
return &cli.Command{
Name: "gitget",
@@ -36,9 +41,13 @@ func GitGet() *cli.Command {
}
if commit != "" {
err = tree.Checkout(&git.CheckoutOptions{
Hash: plumbing.NewHash(commit),
})
checkoutOpts := git.CheckoutOptions{}
if semverRegexp.MatchString(commit) {
checkoutOpts.Branch = plumbing.NewTagReferenceName(commit)
} else {
checkoutOpts.Hash = plumbing.NewHash(commit)
}
err = tree.Checkout(&checkoutOpts)
if err != nil {
return errors.WithMessagef(err, "checkout: %s", commit)
}