Skip to content

Commit b66ac01

Browse files
MarkusHorstmannarturcic
authored andcommitted
Code Review: remove logger from IReferenceCollection
1 parent 626286d commit b66ac01

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/GitVersion.Core/Core/GitPreparer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ private void CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(string remoteName
330330
}
331331
var remoteRefTipId = remoteTrackingReference.ReferenceTargetId;
332332
log.Info($"Updating local ref '{localRef.Name.Canonical}' to point at {remoteRefTipId}.");
333-
repository.Refs.UpdateTarget(localRef, remoteRefTipId, log);
333+
new OperationWithExponentialBackoff<LockedFileException>(new ThreadSleep(), log, () => repository.Refs.UpdateTarget(localRef, remoteRefTipId), maxRetries: 6).ExecuteAsync().Wait();
334334
continue;
335335
}
336336

@@ -383,7 +383,7 @@ public void EnsureLocalBranchExistsForCurrentBranch(IRemote remote, string curre
383383
log.Info(isBranch ? $"Updating local branch {referenceName} to point at {repoTip}"
384384
: $"Updating local branch {referenceName} to match ref {currentBranch}");
385385
var localRef = repository.Refs[localCanonicalName];
386-
repository.Refs.UpdateTarget(localRef, repoTipId, log);
386+
new OperationWithExponentialBackoff<LockedFileException>(new ThreadSleep(), log, () => repository.Refs.UpdateTarget(localRef, repoTipId), maxRetries: 6).ExecuteAsync().Wait();
387387
}
388388

389389
repository.Checkout(localCanonicalName);

src/GitVersion.Core/Git/IReferenceCollection.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using GitVersion.Logging;
2+
using System;
23
using System.Collections.Generic;
34

45
namespace GitVersion
@@ -8,7 +9,14 @@ public interface IReferenceCollection : IEnumerable<IReference>
89
IReference Head { get; }
910
IReference this[string name] { get; }
1011
void Add(string name, string canonicalRefNameOrObjectish, bool allowOverwrite = false);
11-
void UpdateTarget(IReference directRef, IObjectId targetId, ILog log);
12+
void UpdateTarget(IReference directRef, IObjectId targetId);
1213
IEnumerable<IReference> FromGlob(string prefix);
1314
}
15+
16+
public class LockedFileException : Exception
17+
{
18+
public LockedFileException(Exception inner) : base(inner.Message, inner)
19+
{
20+
}
21+
}
1422
}

src/GitVersion.LibGit2Sharp/Git/ReferenceCollection.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using GitVersion.Helpers;
2-
using GitVersion.Logging;
31
using System.Collections;
42
using System.Collections.Generic;
53
using System.Linq;
@@ -21,9 +19,17 @@ public void Add(string name, string canonicalRefNameOrObjectish, bool allowOverw
2119
innerCollection.Add(name, canonicalRefNameOrObjectish, allowOverwrite);
2220
}
2321

24-
public void UpdateTarget(IReference directRef, IObjectId targetId, ILog log)
22+
public void UpdateTarget(IReference directRef, IObjectId targetId)
2523
{
26-
new OperationWithExponentialBackoff<LibGit2Sharp.LockedFileException>(new ThreadSleep(), log, () => innerCollection.UpdateTarget((Reference)directRef, (ObjectId)targetId), maxRetries: 6).ExecuteAsync().Wait();
24+
try
25+
{
26+
innerCollection.UpdateTarget((Reference)directRef, (ObjectId)targetId);
27+
}
28+
catch (LibGit2Sharp.LockedFileException ex)
29+
{
30+
// Wrap this exception so that callers that want to catch it don't need to take a dependency on LibGit2Sharp.
31+
throw new LockedFileException(ex);
32+
}
2733
}
2834

2935
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

0 commit comments

Comments
 (0)