Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Can't commit on a bare repository #692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2014
Merged
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
27 changes: 27 additions & 0 deletions LibGit2Sharp.Tests/RepositoryOptionsFixture.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
Expand Down Expand Up @@ -174,5 +175,31 @@ public void CanProvideDifferentConfigurationFilesToARepository()

AssertValueInConfigFile(systemLocation, "xpaulbettsx");
}

[Fact]
public void CanCommitOnBareRepository()
{
string repoPath = InitNewRepository(true);
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
string workPath = Path.Combine(scd.RootedDirectoryPath, "work");
Directory.CreateDirectory(workPath);

var repositoryOptions = new RepositoryOptions
{
WorkingDirectoryPath = workPath,
IndexPath = Path.Combine(scd.RootedDirectoryPath, "index")
};

using (var repo = new Repository(repoPath, repositoryOptions))
{
const string relativeFilepath = "test.txt";
Touch(repo.Info.WorkingDirectory, relativeFilepath, "test\n");
repo.Index.Stage(relativeFilepath);

Assert.NotNull(repo.Commit("Initial commit", Constants.Signature, Constants.Signature));
Assert.Equal(1, repo.Head.Commits.Count());
Assert.Equal(1, repo.Commits.Count());
}
}
}
}
10 changes: 2 additions & 8 deletions LibGit2Sharp/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -894,14 +894,8 @@ public Commit Commit(string message, Signature author, Signature committer, Comm

Proxy.git_repository_state_cleanup(handle);

var logAllRefUpdates = Config.GetValueOrDefault<bool>("core.logAllRefUpdates", false);
if (!logAllRefUpdates)
{
return result;
}

var logMessage = BuildCommitLogMessage(result, options.AmendPreviousCommit, isHeadOrphaned, parents.Count > 1);
LogCommit(result, logMessage);
UpdateHeadAndTerminalReference(result, logMessage);

return result;
}
Expand All @@ -925,7 +919,7 @@ private static string BuildCommitLogMessage(Commit commit, bool amendPreviousCom
return string.Format(CultureInfo.InvariantCulture, "commit{0}: {1}", kind, commit.MessageShort);
}

private void LogCommit(Commit commit, string reflogMessage)
private void UpdateHeadAndTerminalReference(Commit commit, string reflogMessage)
{
Reference reference = Refs.Head;

Expand Down