简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM