Skip to content

Commit

Permalink
Code Review: remove logger from IReferenceCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusHorstmann authored and arturcic committed Feb 7, 2021
1 parent 626286d commit b66ac01
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/GitVersion.Core/Core/GitPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ private void CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(string remoteName
}
var remoteRefTipId = remoteTrackingReference.ReferenceTargetId;
log.Info($"Updating local ref '{localRef.Name.Canonical}' to point at {remoteRefTipId}.");
repository.Refs.UpdateTarget(localRef, remoteRefTipId, log);
new OperationWithExponentialBackoff<LockedFileException>(new ThreadSleep(), log, () => repository.Refs.UpdateTarget(localRef, remoteRefTipId), maxRetries: 6).ExecuteAsync().Wait();
continue;
}

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

repository.Checkout(localCanonicalName);
Expand Down
10 changes: 9 additions & 1 deletion src/GitVersion.Core/Git/IReferenceCollection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GitVersion.Logging;
using System;
using System.Collections.Generic;

namespace GitVersion
Expand All @@ -8,7 +9,14 @@ public interface IReferenceCollection : IEnumerable<IReference>
IReference Head { get; }
IReference this[string name] { get; }
void Add(string name, string canonicalRefNameOrObjectish, bool allowOverwrite = false);
void UpdateTarget(IReference directRef, IObjectId targetId, ILog log);
void UpdateTarget(IReference directRef, IObjectId targetId);
IEnumerable<IReference> FromGlob(string prefix);
}

public class LockedFileException : Exception
{
public LockedFileException(Exception inner) : base(inner.Message, inner)
{
}
}
}
14 changes: 10 additions & 4 deletions src/GitVersion.LibGit2Sharp/Git/ReferenceCollection.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using GitVersion.Helpers;
using GitVersion.Logging;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -21,9 +19,17 @@ public void Add(string name, string canonicalRefNameOrObjectish, bool allowOverw
innerCollection.Add(name, canonicalRefNameOrObjectish, allowOverwrite);
}

public void UpdateTarget(IReference directRef, IObjectId targetId, ILog log)
public void UpdateTarget(IReference directRef, IObjectId targetId)
{
new OperationWithExponentialBackoff<LibGit2Sharp.LockedFileException>(new ThreadSleep(), log, () => innerCollection.UpdateTarget((Reference)directRef, (ObjectId)targetId), maxRetries: 6).ExecuteAsync().Wait();
try
{
innerCollection.UpdateTarget((Reference)directRef, (ObjectId)targetId);
}
catch (LibGit2Sharp.LockedFileException ex)
{
// Wrap this exception so that callers that want to catch it don't need to take a dependency on LibGit2Sharp.
throw new LockedFileException(ex);
}
}

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
Expand Down

0 comments on commit b66ac01

Please sign in to comment.