Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion LibGit2Sharp.Tests/CommitFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ public void CanCommitALittleBit()
AssertBlobContent(commit[relativeFilepath], "nulltoken\n");

Assert.Equal(0, commit.Parents.Count());
Assert.False(repo.Info.IsEmpty);
Assert.False(repo.Info.IsHeadOrphaned);

File.WriteAllText(filePath, "nulltoken commits!\n");
repo.Index.Stage(relativeFilepath);
Expand Down Expand Up @@ -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());
}
}
}
}
2 changes: 0 additions & 2 deletions LibGit2Sharp.Tests/RepositoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public void CreatingRepoWithBadParamsThrows()
private static void AssertInitializedRepository(Repository repo)
{
Assert.NotNull(repo.Info.Path);
Assert.True(repo.Info.IsEmpty);
Assert.False(repo.Info.IsHeadDetached);
Assert.True(repo.Info.IsHeadOrphaned);

Expand Down Expand Up @@ -215,7 +214,6 @@ public void CanOpenRepository()
Assert.NotNull(repo.Info.Path);
Assert.Null(repo.Info.WorkingDirectory);
Assert.True(repo.Info.IsBare);
Assert.False(repo.Info.IsEmpty);
Assert.False(repo.Info.IsHeadDetached);
}
}
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/TagFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ public void CanListAllTagsInAEmptyRepository()

using (var repo = Repository.Init(scd.DirectoryPath))
{
Assert.True(repo.Info.IsEmpty);
Assert.True(repo.Info.IsHeadOrphaned);
Assert.Equal(0, repo.Tags.Count());
}
}
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ public void Reset(Commit commit, IEnumerable<string> paths = null)
/// <returns>The generated <see cref = "Commit" />.</returns>
public Commit Commit(string message, Signature author, Signature committer, bool amendPreviousCommit = false)
{
if (amendPreviousCommit && Info.IsEmpty)
if (amendPreviousCommit && Info.IsHeadOrphaned)
{
throw new LibGit2SharpException("Can not amend anything. The Head doesn't point at any commit.");
}
Expand All @@ -681,7 +681,7 @@ private IEnumerable<Commit> RetrieveParentsOfTheCommitBeingCreated(bool amendPre
return Head.Tip.Parents;
}

if (Info.IsEmpty)
if (Info.IsHeadOrphaned)
{
return Enumerable.Empty<Commit>();
}
Expand Down
4 changes: 3 additions & 1 deletion LibGit2Sharp/RepositoryInformation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LibGit2Sharp.Core;
using System;
using LibGit2Sharp.Core;

namespace LibGit2Sharp
{
Expand Down Expand Up @@ -51,6 +52,7 @@ internal RepositoryInformation(Repository repo, bool isBare)
/// <value>
/// <c>true</c> if this repository is empty; otherwise, <c>false</c>.
/// </value>
[Obsolete("This method will be removed in the next release.")]
public virtual bool IsEmpty
{
get { return Proxy.git_repository_is_empty(repo.Handle); }
Expand Down