Permalink
Browse files

Allow commits on any unparented branch

  • Loading branch information...
1 parent 46a5c17 commit 813be8d71992db601c32d896179d53a5eeed8ad9 @jamill jamill committed with nulltoken Feb 26, 2013
Showing with 24 additions and 1 deletion.
  1. +23 −0 LibGit2Sharp.Tests/CommitFixture.cs
  2. +1 −1 LibGit2Sharp/Repository.cs
@@ -814,5 +814,28 @@ public void CanCorrectlyDistinguishAuthorFromCommitter()
Assert.Equal(committer, c.Committer);
}
}
+
+ [Fact]
+ public void CanCommitOnOrphanedBranch()
+ {
+ string newBranchName = "refs/heads/newBranch";
+ SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
+
+ using (var repo = Repository.Init(scd.DirectoryPath))
+ {
+ // Set Head to point to branch other than master
+ repo.Refs.UpdateTarget("HEAD", newBranchName);
+ Assert.Equal(newBranchName, repo.Head.CanonicalName);
+
+ const string relativeFilepath = "test.txt";
+ string filePath = Path.Combine(repo.Info.WorkingDirectory, relativeFilepath);
+
+ File.WriteAllText(filePath, "test\n");
+ repo.Index.Stage(relativeFilepath);
+
+ repo.Commit("Initial commit", DummySignature, DummySignature);
+ Assert.Equal(1, repo.Head.Commits.Count());
+ }
+ }
}
}
@@ -697,7 +697,7 @@ private IEnumerable<Commit> RetrieveParentsOfTheCommitBeingCreated(bool amendPre
return Head.Tip.Parents;
}
- if (Info.IsEmpty)
+ if (Info.IsHeadOrphaned)
{
return Enumerable.Empty<Commit>();
}

0 comments on commit 813be8d

Please sign in to comment.