diff options
-rw-r--r-- | LibGit2Sharp.Tests/BranchFixture.cs | 44 | ||||
-rw-r--r-- | LibGit2Sharp/BranchCollection.cs | 3 |
2 files changed, 43 insertions, 4 deletions
diff --git a/LibGit2Sharp.Tests/BranchFixture.cs b/LibGit2Sharp.Tests/BranchFixture.cs index 4630f6fd..3febeaff 100644 --- a/LibGit2Sharp.Tests/BranchFixture.cs +++ b/LibGit2Sharp.Tests/BranchFixture.cs @@ -161,7 +161,26 @@ namespace LibGit2Sharp.Tests { using (var repo = new Repository(Constants.TestRepoPath)) { - Assert.Throws<ArgumentException>(() => repo.Branches.Create(string.Empty, "not_important_sha")); + Assert.Throws<ArgumentException>(() => repo.Branches.Create(string.Empty, repo.Head.ResolveToDirectReference().TargetIdentifier)); + } + } + + [Test] + [Ignore("Not implemented yet.")] + public void CreatingBranchWithUnknownNamedTargetThrows() + { + using (var repo = new Repository(Constants.TestRepoPath)) + { + Assert.Throws<ArgumentException>(() => repo.Branches.Create("my_new_branch", "my_old_branch")); + } + } + + [Test] + public void CreatingBranchWithUnknownShaTargetThrows() + { + using (var repo = new Repository(Constants.TestRepoPath)) + { + Assert.Throws<ApplicationException>(() => repo.Branches.Create("my_new_branch", Constants.UnknownSha)); } } @@ -179,7 +198,7 @@ namespace LibGit2Sharp.Tests { using (var repo = new Repository(Constants.TestRepoPath)) { - Assert.Throws<ArgumentNullException>(() => repo.Branches.Create(null, "not_important_sha")); + Assert.Throws<ArgumentNullException>(() => repo.Branches.Create(null, repo.Head.ResolveToDirectReference().TargetIdentifier)); } } @@ -260,6 +279,7 @@ namespace LibGit2Sharp.Tests repo.Branches["br3"].ShouldNotBeNull(); } } + [Test] public void BlindlyMovingABranchOverAnExistingOneThrows() { @@ -294,5 +314,23 @@ namespace LibGit2Sharp.Tests newTest.Tip.ShouldEqual(br2.Tip); } } + + [Test] + public void CreatingABranchTriggersTheCreationOfADirectReference() + { + using (var path = new TemporaryCloneOfTestRepo()) + using (var repo = new Repository(path.RepositoryPath)) + { + var newBranch = repo.CreateBranch("clone-of-master"); + newBranch.IsCurrentRepositoryHead.ShouldBeFalse(); + + var commitId = repo.Head.ResolveToDirectReference().TargetIdentifier; + newBranch.Tip.Sha.ShouldEqual(commitId); + + var reference = repo.Refs[newBranch.CanonicalName]; + reference.ShouldNotBeNull(); + Assert.IsInstanceOf(typeof (DirectReference), reference); + } + } } -}
\ No newline at end of file +} diff --git a/LibGit2Sharp/BranchCollection.cs b/LibGit2Sharp/BranchCollection.cs index ecf9b3a7..833db24d 100644 --- a/LibGit2Sharp/BranchCollection.cs +++ b/LibGit2Sharp/BranchCollection.cs @@ -83,7 +83,8 @@ namespace LibGit2Sharp if (id == null) { - target = NormalizeToCanonicalName(target); + var reference = repo.Refs[NormalizeToCanonicalName(target)].ResolveToDirectReference(); + target = reference.TargetIdentifier; } repo.Refs.Create(NormalizeToCanonicalName(name), target); |