0

I'm aware of how to checkout a specific commit or branch using Checkout(&git.checkoutOptions) with plumbing.ReferenceName("<branchName>") or plumbing.Hash("<commit hash>"), but I want to be able to clone a specific release version. Any ideas on how to do this?

torek
  • 448,244
  • 59
  • 642
  • 775
moho1357
  • 3
  • 3

1 Answers1

0

You will need to set ReferenceName in CloneOptions.

Example cloning v4.1 of git-go:

r, err := git.PlainClone("/tmp/foo", false, &git.CloneOptions{
        URL:      "https://github.com/go-git/go-git",
        ReferenceName: plumbing.ReferenceName("refs/tags/v4.1.0"),
        Progress: os.Stdout,
})
itsmaleen
  • 35
  • 5
  • Thanks! Do you have any ideas around making this dynamic; e.g does go-git have any internals that will help me replace v4.1.0 with something like "latest", or will I have to save the latest release myself – moho1357 Aug 18 '21 at 19:46
  • If you don't set `ReferenceName` (remove that entire line), it will clone from master which should be latest – itsmaleen Aug 18 '21 at 19:55
  • For this specific repo master is not what we want to access since it won't necessarily be the same as the latest release version. I want to be able to checkout the latest release version (which will have the latest tag) . – moho1357 Aug 18 '21 at 20:01
  • 1
    Given a repository with tags "alpha4" and "gamma7" and "v3.1", which is the latest? But: see [How to compare two version number strings in golang](https://stackoverflow.com/q/18409373/1256452). – torek Aug 19 '21 at 01:23