Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2011-06-01 23:36:29 +0400
committernulltoken <emeric.fermas@gmail.com>2011-06-01 23:36:29 +0400
commita1f568b69c43659171d987ce0c4ffb7bd0bf8bc0 (patch)
tree2a4d5ce9c3b82c2aa45b1d6992cfc24d43ed5b23
parentd9a871ea3b067fa3dfb9a12a710c804397d8794d (diff)
Fix a branch creation issue
When being passed another branch as a starting point the creation process now dereferences the branch instead of creating a symbolic reference.
-rw-r--r--LibGit2Sharp.Tests/BranchFixture.cs44
-rw-r--r--LibGit2Sharp/BranchCollection.cs3
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);