8000 Respect core.logAllRefUpdates · philhack/libgit2sharp@726266a · GitHub
[go: up one dir, main page]

Skip to content

Commit 726266a

Browse files
committed
Respect core.logAllRefUpdates
1 parent ddec9f0 commit 726266a

File tree

6 files changed

+76
-1
lines changed

6 files changed

+76
-1
lines changed

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public void CanCreateBranch(string name)
2020
string path = CloneBareTestRepo();
2121
using (var repo = new Repository(path))
2222
{
23+
EnableRefLog(repo);
24+
2325
const string committish = "be3563ae3f795b2b4353bcce3a527ad0a4f7f644";
2426

2527
Branch newBranch = repo.CreateBranch(name, committish);
@@ -46,6 +48,8 @@ public void CanCreateBranchUsingAbbreviatedSha()
4648
string path = CloneBareTestRepo();
4749
using (var repo = new Repository(path))
4850
{
51+
EnableRefLog(repo);
52+
4953
const string name = "unit_test";
5054
const string committish = "be3563a";
5155

@@ -68,6 +72,8 @@ public void CanCreateBranchFromImplicitHead(string headCommitOrBranchSpec)
6872
string path = CloneStandardTestRepo();
6973
using (var repo = new Repository(path))
7074
{
75+
EnableRefLog(repo);
76+
7177
repo.Checkout(headCommitOrBranchSpec);
7278

7379
const string name = "unit_test";
@@ -95,6 +101,8 @@ public void CanCreateBranchFromExplicitHead(string headCommitOrBranchSpec)
95101
string path = CloneStandardTestRepo();
96102
using (var repo = new Repository(path))
97103
{
104+
EnableRefLog(repo);
105+
98106
repo.Checkout(headCommitOrBranchSpec);
99107

100108
const string name = "unit_test";
@@ -115,6 +123,8 @@ public void CanCreateBranchFromCommit()
115123
string path = CloneBareTestRepo();
116124
using (var repo = new Repository(path))
117125
{
126+
EnableRefLog(repo);
127+
118128
const string name = "unit_test";
119129
var commit = repo.Lookup<Commit>("HEAD");
120130
Branch newBranch = repo.CreateBranch(name, commit);
@@ -134,6 +144,8 @@ public void CanCreateBranchFromRevparseSpec()
134144
string path = CloneBareTestRepo();
135145
using (var repo = new Repository(path))
136146
{
147+
EnableRefLog(repo);
148+
137149
const string name = "revparse_branch";
138150
const string committish = "master~2";
139151

@@ -156,6 +168,8 @@ public void CreatingABranchFromATagPeelsToTheCommit(string committish)
156168
string path = CloneBareTestRepo();
157169
using (var repo = new Repository(path))
158170
{
171+
EnableRefLog(repo);
172+
159173
const string name = "i-peel-tag";
160174

161175
Branch newBranch = repo.CreateBranch(name, committish);
@@ -777,6 +791,8 @@ public void CanMoveABranch()
777791
string path = CloneBareTestRepo();
778792
using (var repo = new Repository(path))
779793
{
794+
EnableRefLog(repo);
795+
780796
Assert.Null(repo.Branches["br3"]);
781797
var br2 = repo.Branches["br2"];
782798
Assert.NotNull(br2);
@@ -810,6 +826,8 @@ public void CanMoveABranchWhileOverwritingAnExistingOne()
810826
string path = CloneBareTestRepo();
811827
using (var repo = new Repository(path))
812828
{
829+
EnableRefLog(repo);
830+
813831
Branch test = repo.Branches["test"];
814832
Assert.NotNull(test);
815833

LibGit2Sharp.Tests/FilterBranchFixture.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ public void CanRewriteParentWithRewrittenCommit()
474474
[Fact]
475475
public void WritesCorrectReflogMessagesForSimpleRewrites()
476476
{
477+
EnableRefLog(repo);
478+
477479
repo.Refs.RewriteHistory(new RewriteHistoryOptions
478480
{
479481
CommitHeaderRewriter =

LibGit2Sharp.Tests/ReferenceFixture.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public void CanAddADirectReferenceFromRevParseSpec()
4343
string path = CloneBareTestRepo();
4444
using (var repo = new Repository(path))
4545
{
46+
EnableRefLog(repo);
47+
4648
var newRef = (DirectReference)repo.Refs.Add(name, "master^1^2", logMessage: logMessage);
4749
Assert.NotNull(newRef);
4850
Assert.Equal(name, newRef.CanonicalName);
@@ -94,6 +96,8 @@ public void CanAddASymbolicReferenceFromTheTargetReference()
9496
string path = CloneBareTestRepo();
9597
using (var repo = new Repository(path))
9698
{
99+
EnableRefLog(repo);
100+
97101
var targetRef = repo.Refs[target];
98102

99103
var newRef = repo.Refs.Add(name, targetRef, logMessage: logMessage);
@@ -146,6 +150,8 @@ public void CanAddAndOverwriteADirectReference()
146150
string path = CloneBareTestRepo();
147151
using (var repo = new Repository(path))
148152
{
153+
EnableRefLog(repo);
154+
149155
var newRef = (DirectReference)repo.Refs.Add(name, target, true, logMessage);
150156
Assert.NotNull(newRef);
151157
Assert.Equal(name, newRef.CanonicalName);
@@ -169,6 +175,8 @@ public void CanAddAndOverwriteASymbolicReference()
169175
string path = CloneBareTestRepo();
170176
using (var repo = new Repository(path))
171177
{
178+
EnableRefLog(repo);
179+
172180
var newRef = (SymbolicReference)repo.Refs.Add(name, target, true, logMessage);
173181
Assert.NotNull(newRef);
174182
Assert.Equal(name, newRef.CanonicalName);
@@ -473,6 +481,8 @@ public void CanUpdateHeadWithEitherAnObjectIdOrAReference()
473481
string path = CloneBareTestRepo();
474482
using (var repo = new Repository(path))
475483
{
484+
EnableRefLog(repo);
485+
476486
Reference head = repo.Refs.Head;
477487
Reference test = repo.Refs["refs/heads/test"];
478488

@@ -506,6 +516,8 @@ public void CanUpdateTargetOfADirectReferenceWithARevparseSpec()
506516
string path = CloneBareTestRepo();
507517
using (var repo = new Repository(path))
508518
{
519+
EnableRefLog(repo);
520+
509521
const string name = "refs/heads/master";
510522

511523
var master = (DirectReference) repo.Refs[name];

LibGit2Sharp.Tests/ReflogFixture.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using System.Linq;
1+
using System.IO;
2+
using System.Linq;
23
using LibGit2Sharp.Tests.TestHelpers;
34
using Xunit;
5+
using Xunit.Extensions;
46

57
namespace LibGit2Sharp.Tests
68
{
@@ -126,5 +128,35 @@ public void CommitOnDetachedHeadShouldInsertReflogEntry()
126128
Assert.Equal(string.Format("commit: {0}", commitMessage), repo.Refs.Log("HEAD").First().Message);
127129
}
128130
}
131+
132+
[Theory]
133+
[InlineData(false, null, true)]
134+
[InlineData(false, false, false)]
135+
[InlineData(false, true, true)]
136+
[InlineData(true, null, false)]
137+
[InlineData(true, false, false)]
138+
[InlineData(true, true, true)]
139+
public void AppendingToReflogDependsOnCoreLogAllRefUpdatesSetting(bool isBare, bool? setting, bool expectAppend)
140+
{
141+
var repoPath = InitNewRepository(isBare);
142+
143+
using (var repo = new Repository(repoPath))
144+
{
145+
if (setting != null)
146+
{
147+
EnableRefLog(repo, setting.Value);
148+
}
149+
150+
var blob = repo.ObjectDatabase.CreateBlob(Stream.Null);
151+
var tree = repo.ObjectDatabase.CreateTree(new TreeDefinition().Add("yoink", blob, Mode.NonExecutableFile));
152+
var commit = repo.ObjectDatabase.CreateCommit("yoink", Constants.Signature, Constants.Signature,
153+
tree, Enumerable.Empty<Commit>());
154+
155+
var branch = repo.CreateBranch("yoink", commit);
156+
var log = repo.Refs.Log(branch.CanonicalName);
157+
158+
Assert.Equal(expectAppend ? 1 : 0, log.Count());
159+
}
160+
}
129161
}
130162
}

LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,5 +261,10 @@ protected static void AssertRefLogEntry(Repository repo, string canonicalName,
261261
Assert.Equal(committer, reflogEntry.Commiter);
262262
}
263263
}
264+
265+
protected static void EnableRefLog(Repository repository, bool enable = true)
266+
{
267+
repository.Config.Set("core.logAllRefUpdates", enable);
268+
}
264269
}
265270
}

LibGit2Sharp/ReflogCollection.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ private string DebuggerDisplay
9797
/// <param name="committer"><see cref="Signature"/> of the comitter.</param>
9898
internal virtual void Append(ObjectId target, string reflogMessage, Signature committer)
9999
{
100+
var logAllRefUpdates = repo.Config.GetValueOrDefault<bool>("core.logAllRefUpdates", false);
101+
if (!logAllRefUpdates)
102+
{
103+
return;
104+
}
105+
100106
using (ReferenceSafeHandle reference = Proxy.git_reference_lookup(repo.Handle, canonicalName, true))
101107
using (ReflogSafeHandle reflog = Proxy.git_reflog_read(reference))
102108
{

0 commit comments

Comments
 (0)
0