diff options
-rw-r--r-- | LibGit2Sharp.Tests/CloneFixture.cs | 20 | ||||
-rw-r--r-- | LibGit2Sharp/CloneOptions.cs | 6 | ||||
-rw-r--r-- | LibGit2Sharp/Repository.cs | 1 |
3 files changed, 27 insertions, 0 deletions
diff --git a/LibGit2Sharp.Tests/CloneFixture.cs b/LibGit2Sharp.Tests/CloneFixture.cs index a78a238c..b5ce91bb 100644 --- a/LibGit2Sharp.Tests/CloneFixture.cs +++ b/LibGit2Sharp.Tests/CloneFixture.cs @@ -36,6 +36,26 @@ namespace LibGit2Sharp.Tests } } + [Theory] + [InlineData("br2", "a4a7dce85cf63874e984719f4fdd239f5145052f")] + [InlineData("packed", "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9")] + [InlineData("test", "e90810b8df3e80c413d903f631643c716887138d")] + public void CanCloneWithCheckoutBranchName(string branchName, string headTipId) + { + var scd = BuildSelfCleaningDirectory(); + + string clonedRepoPath = Repository.Clone(BareTestRepoPath, scd.DirectoryPath, new CloneOptions { BranchName = branchName }); + + using (var repo = new Repository(clonedRepoPath)) + { + var head = repo.Head; + + Assert.Equal(branchName, head.Name); + Assert.True(head.IsTracking); + Assert.Equal(headTipId, head.Tip.Sha); + } + } + private void AssertLocalClone(string url, string path = null, bool isCloningAnEmptyRepository = false) { var scd = BuildSelfCleaningDirectory(); diff --git a/LibGit2Sharp/CloneOptions.cs b/LibGit2Sharp/CloneOptions.cs index ce176eaa..779fef99 100644 --- a/LibGit2Sharp/CloneOptions.cs +++ b/LibGit2Sharp/CloneOptions.cs @@ -29,6 +29,12 @@ namespace LibGit2Sharp public bool Checkout { get; set; } /// <summary> + /// The name of the branch to checkout. When unspecified the + /// remote's default branch will be used instead. + /// </summary> + public string BranchName { get; set; } + + /// <summary> /// Handler for checkout progress information. /// </summary> public CheckoutProgressHandler OnCheckoutProgress { get; set; } diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index d92aed91..ac792284 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -553,6 +553,7 @@ namespace LibGit2Sharp Bare = options.IsBare ? 1 : 0, CheckoutOpts = gitCheckoutOptions, RemoteCallbacks = gitRemoteCallbacks, + CheckoutBranch = StrictUtf8Marshaler.FromManaged(options.BranchName) }; FilePath repoPath; |