8000 Allow commits on any unparented branch · mm201/libgit2sharp@813be8d · GitHub
[go: up one dir, main page]

Skip to content

Commit 813be8d

Browse files
jamillnulltoken
authored andcommitted
Allow commits on any unparented branch
1 parent 46a5c17 commit 813be8d

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,5 +814,28 @@ public void CanCorrectlyDistinguishAuthorFromCommitter()
814814
Assert.Equal(committer, c.Committer);
815815
}
816816
}
817+
818+
[Fact]
819+
public void CanCommitOnOrphanedBranch()
820+
{
821+
string newBranchName = "refs/heads/newBranch";
822+
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
823+
824+
using (var repo = Repository.Init(scd.DirectoryPath))
825+
{
826+
// Set Head to point to branch other than master
827+
repo.Refs.UpdateTarget("HEAD", newBranchName);
828+
Assert.Equal(newBranchName, repo.Head.CanonicalName);
829+
830+
const string relativeFilepath = "test.txt";
831+
string filePath = Path.Combine(repo.Info.WorkingDirectory, relativeFilepath);
832+
833+
File.WriteAllText(filePath, "test\n");
834+
repo.Index.Stage(relativeFilepath);
835+
836+
repo.Commit("Initial commit", DummySignature, DummySignature);
837+
Assert.Equal(1, repo.Head.Commits.Count());
838+
}
839+
}
817840
}
818841
}

LibGit2Sharp/Repository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ private IEnumerable<Commit> RetrieveParentsOfTheCommitBeingCreated(bool amendPre
697697
return Head< 5F81 span class=pl-kos>.Tip.Parents;
698698
}
699699

700-
if (Info.IsEmpty)
700+
if (Info.IsHeadOrphaned)
701701
{
702702
return Enumerable.Empty<Commit>();
703703
}

0 commit comments

Comments
 (0)
0