LND
LND

Reputation: 152

Is it possible to clone from a specific tag using Libgit2sharp?

Using LibGit2Sharp, I can do a clone from a specific remote branch :). Now, I want to clone a repo from a specif tag, say "v1". I found this link but it does not help me. how to clone specific tag using git_clone() in libgit2

I thought I might be able to specifiy the tag with CloneOptions.BranchName (I know this is for a branch but I thought I should try anyway before posting my question) but it did not succeed. Here's the C# code I have.

        var co = new CloneOptions();
        co.BranchName = "v1"; // "refs/tags/v1" does not work either
        co.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials { Username = "username", Password = "password" };
        Repository.Clone(repoUrl, localGitPath, co);

Is it possible to clone from a specific tag?

Upvotes: 4

Views: 420

Answers (1)

Kebechet
Kebechet

Reputation: 2387

From what I found you cant directly Clone repo based on tag. But you can make a clone of the branch and then checkout to the tag specified. Something like:

var repositoryOptions = new RepositoryOptions { WorkingDirectoryPath = <projectRepositoryPath> };
var checkoutOptions = new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force};

using (var repo = new Repository(<projectRepositoryPath>, repositoryOptions))
{ 
    var result = Commands.Checkout(repo, <commitSpecifier>, checkoutOptions);
}

where commitSpecifier is the tag name and projectRepositoryPath is the path to your local repository directory

Upvotes: 1

Related Questions