Skip to content

Commit 6c09292

Browse files
mumitrollernulltoken
authored andcommitted
Fix Commit() so that it always updates the HEAD
Fix #692
1 parent 989f953 commit 6c09292

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

LibGit2Sharp.Tests/RepositoryOptionsFixture.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
34
using System.Text;
45
using LibGit2Sharp.Tests.TestHelpers;
56
using Xunit;
@@ -174,5 +175,38 @@ public void CanProvideDifferentConfigurationFilesToARepository()
174175

175176
AssertValueInConfigFile(systemLocation, "xpaulbettsx");
176177
}
178+
179+
[Fact]
180+
public void CanCommitOnBareRepository()
181+
{
182+
string repoPath = InitNewRepository(true);
183+
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
184+
string workPath = Path.Combine(scd.RootedDirectoryPath, "work");
185+
Directory.CreateDirectory(workPath);
186+
187+
var repositoryOptions = new RepositoryOptions
188+
{
189+
WorkingDirectoryPath = workPath,
190+
IndexPath = Path.Combine(scd.RootedDirectoryPath, "index")
191+
};
192+
193+
using (var repo = new Repository(repoPath, repositoryOptions))
194+
{
195+
const string relativeFilepath = "test.txt";
196+
Touch(repo.Info.WorkingDirectory, relativeFilepath, "test\n");
197+
repo.Index.Stage(relativeFilepath);
198+
199+
Assert.NotNull(repo.Commit("Initial commit", Constants.Signature, Constants.Signature));
200+
Assert.Equal(1, repo.Head.Commits.Count());
201+
Assert.Equal(1, repo.Commits.Count());
202+
203+
// However, as we're in a bare repository, by default core.logallrefupdates is unset
204+
Assert.Null(repo.Config.Get<bool>("core.logallrefupdates"));
205+
206+
// TODO: Uncomment these lines once this is handled at the libgit2 level
207+
//Assert.Equal(0, repo.Refs.Log("refs/heads/master").Count());
208+
//Assert.Equal(0, repo.Refs.Log("HEAD").Count());
209+
}
210+
}
177211
}
178212
}

LibGit2Sharp/Repository.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -894,12 +894,6 @@ public Commit Commit(string message, Signature author, Signature committer, Comm
894894

895895
Proxy.git_repository_state_cleanup(handle);
896896

897-
var logAllRefUpdates = Config.GetValueOrDefault<bool>("core.logAllRefUpdates", false);
898-
if (!logAllRefUpdates)
899-
{
900-
return result;
901-
}
902-
903897
var logMessage = BuildCommitLogMessage(result, options.AmendPreviousCommit, isHeadOrphaned, parents.Count > 1);
904898
LogCommit(result, logMessage);
905899

0 commit comments

Comments
 (0)