Skip to content

Commit a7fe235

Browse files
Make VersionVariables.FromFile work with no logger. Preserve exception.
1 parent 854b5c0 commit a7fe235

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

src/GitVersion.Core/Helpers/OperationWithExponentialBackoff.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public OperationWithExponentialBackoff(IThreadSleep threadSleep, ILog log, Actio
1616
{
1717
return base.ExecuteAsync();
1818
}
19-
2019
}
2120
public class OperationWithExponentialBackoff<T, Result> where T : Exception
2221
{

src/GitVersion.Core/Model/VersionVariables.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,25 @@ public static VersionVariables FromJson(string json)
168168

169169
public static VersionVariables FromFile(string filePath, IFileSystem fileSystem, ILog log)
170170
{
171-
var retryOperation = new OperationWithExponentialBackoff<IOException, VersionVariables>(new ThreadSleep(), log, () => FromFileInternal(filePath, fileSystem));
172-
var versionVariables = retryOperation.ExecuteAsync().Result;
173-
return versionVariables;
171+
try
172+
{
173+
if (log == null)
174+
{
175+
return FromFileInternal(filePath, fileSystem);
176+
}
177+
var retryOperation = new OperationWithExponentialBackoff<IOException, VersionVariables>(new ThreadSleep(), log, () => FromFileInternal(filePath, fileSystem));
178+
var versionVariables = retryOperation.ExecuteAsync().Result;
179+
return versionVariables;
180+
}
181+
catch (AggregateException ex)
182+
{
183+
var lastException = ex.InnerExceptions?.LastOrDefault() ?? ex.InnerException;
184+
if (lastException != null)
185+
{
186+
throw lastException;
187+
}
188+
throw;
189+
}
174190
}
175191
private static VersionVariables FromFileInternal(string filePath, IFileSystem fileSystem)
176192
{

src/GitVersion.LibGit2Sharp/Git/GitRepository.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,13 @@ public ICommit FindMergeBase(ICommit commit, ICommit otherCommit)
6060
return new Commit(mergeBase);
6161
}).ExecuteAsync().Result;
6262
}
63-
6463
public int GetNumberOfUncommittedChanges()
6564
{
6665
return new OperationWithExponentialBackoff<LibGit2Sharp.LockedFileException, int>(new ThreadSleep(), log, () =>
6766
{
6867
return GetNumberOfUncommittedChangesInternal();
6968
}).ExecuteAsync().Result;
7069
}
71-
7270
private int GetNumberOfUncommittedChangesInternal()
7371
{
7472
// check if we have a branch tip at all to behave properly with empty repos
@@ -87,26 +85,24 @@ private int GetNumberOfUncommittedChangesInternal()
8785
catch (Exception)
8886
{
8987
return int.MaxValue; // this should be somewhat puzzling to see,
90-
// so we may have reached our goal to show that
91-
// that repo is really "Dirty"...
88+
// so we may have reached our goal to show that
89+
// that repo is really "Dirty"...
9290
}
9391
}
9492

9593
// gets all changes of the last commit vs Staging area and WT
9694
var changes = repositoryInstance.Diff.Compare<TreeChanges>(repositoryInstance.Head.Tip.Tree,
97-
DiffTargets.Index | DiffTargets.WorkingDirectory);
95+
DiffTargets.Index | DiffTargets.WorkingDirectory);
9896

9997
return changes.Count;
10098
}
101-
10299
public void CreateBranchForPullRequestBranch(AuthenticationInfo auth)
103100
{
104101
new OperationWithExponentialBackoff<LockedFileException>(new ThreadSleep(), log, () =>
105102
{
106103
CreateBranchForPullRequestBranchInternal(auth);
107104
}).ExecuteAsync().Wait();
108105
}
109-
110106
private void CreateBranchForPullRequestBranchInternal(AuthenticationInfo auth)
111107
{
112108
var network = repositoryInstance.Network;
@@ -164,7 +160,6 @@ private void CreateBranchForPullRequestBranchInternal(AuthenticationInfo auth)
164160
throw new WarningException(message);
165161
}
166162
}
167-
168163
public void Clone(string sourceUrl, string workdirPath, AuthenticationInfo auth)
169164
{
170165
try
@@ -198,7 +193,6 @@ public void Checkout(string commitOrBranchSpec)
198193
{
199194
new OperationWithExponentialBackoff<LockedFileException>(new ThreadSleep(), log, () => Commands.Checkout(repositoryInstance, commitOrBranchSpec)).ExecuteAsync().Wait();
200195
}
201-
202196
public void Fetch(string remote, IEnumerable<string> refSpecs, AuthenticationInfo auth, string logMessage)
203197
{
204198
new OperationWithExponentialBackoff<LockedFileException>(new ThreadSleep(), log, () => Commands.Fetch((Repository)repositoryInstance, remote, refSpecs, GetFetchOptions(auth), logMessage)).ExecuteAsync().Wait();

0 commit comments

Comments
 (0)