Skip to content

Commit 9437513

Browse files
committed
fix GitPrepare injection
1 parent f05ae26 commit 9437513

12 files changed

+35
-35
lines changed

src/GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using GitVersion;
1414
using GitVersion.Configuration.Init.Wizard;
1515
using GitVersion.Logging;
16+
using Microsoft.Extensions.Options;
1617

1718
namespace GitVersionCore.Tests
1819
{
@@ -37,7 +38,7 @@ public void Setup()
3738
configFileLocator = new DefaultConfigFileLocator(fileSystem, log);
3839
repoPath = DefaultRepoPath;
3940

40-
var gitPreparer = new GitPreparer(log, new Arguments { TargetPath = repoPath });
41+
var gitPreparer = new GitPreparer(log, Options.Create(new Arguments { TargetPath = repoPath }));
4142
configurationProvider = new ConfigurationProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard);
4243

4344
ShouldlyConfiguration.ShouldMatchApprovedDefaults.LocateTestMethodUsingAttribute<TestAttribute>();
@@ -292,7 +293,7 @@ public void NoWarnOnGitVersionYmlFile()
292293
var log = new Log(logAppender);
293294

294295
var defaultConfigFileLocator = new DefaultConfigFileLocator(fileSystem, log);
295-
var gitPreparer = new GitPreparer(log, new Arguments { TargetPath = repoPath });
296+
var gitPreparer = new GitPreparer(log, Options.Create(new Arguments { TargetPath = repoPath }));
296297

297298
configurationProvider = new ConfigurationProvider(fileSystem, log, defaultConfigFileLocator, gitPreparer, configInitWizard);
298299

src/GitVersionCore.Tests/DefaultConfigFileLocatorTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using GitVersion;
88
using GitVersion.Configuration.Init.Wizard;
99
using GitVersion.Logging;
10+
using Microsoft.Extensions.Options;
1011

1112
namespace GitVersionCore.Tests
1213
{
@@ -91,8 +92,8 @@ public void NoWarnOnGitVersionYmlFile()
9192
{
9293
var log = new NullLog();
9394
var defaultConfigFileLocator = new DefaultConfigFileLocator(fileSystem, log);
94-
var gitPreparer = new GitPreparer(log, new Arguments { TargetPath = repoPath });
95-
var stepFactory = new ConfigInitStepFactory();
95+
var gitPreparer = new GitPreparer(log, Options.Create(new Arguments { TargetPath = repoPath }));
96+
var stepFactory = new ConfigInitStepFactory();
9697
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
9798

9899
var configurationProvider = new ConfigurationProvider(fileSystem, log, defaultConfigFileLocator, gitPreparer, configInitWizard);

src/GitVersionCore.Tests/DynamicRepositoryTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void FindsVersionInDynamicRepo(string name, string url, string targetBran
9494
var nextVersionCalculator = new NextVersionCalculator(log, metadataCalculator, baseVersionCalculator, mainlineVersionCalculator);
9595
var gitVersionFinder = new GitVersionFinder(log, nextVersionCalculator);
9696

97-
var gitPreparer = new GitPreparer(log, arguments);
97+
var gitPreparer = new GitPreparer(log, options);
9898
var stepFactory = new ConfigInitStepFactory();
9999
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
100100

src/GitVersionCore.Tests/GitToolsTestingExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using GitVersion.SemanticVersioning;
1111
using GitVersion.VersionCalculation;
1212
using GitVersionCore.Tests.VersionCalculation;
13+
using Microsoft.Extensions.Options;
1314

1415
namespace GitVersionCore.Tests
1516
{
@@ -99,7 +100,7 @@ public static void InitializeRepo(this RemoteRepositoryFixture fixture)
99100
Authentication = new Authentication(),
100101
TargetPath = fixture.LocalRepositoryFixture.RepositoryPath
101102
};
102-
new GitPreparer(log, arguments).Prepare(true, null);
103+
new GitPreparer(log, Options.Create(arguments)).Prepare(true, null);
103104
}
104105
}
105106
}

src/GitVersionCore.Tests/GitVersionExecutorTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void CacheKeySameAfterReNormalizing()
6363
TargetUrl = targetUrl,
6464
TargetPath = fixture.RepositoryPath
6565
};
66-
var gitPreparer = new GitPreparer(log, arguments);
66+
var gitPreparer = new GitPreparer(log, Options.Create(arguments));
6767
configFileLocator = new DefaultConfigFileLocator(fileSystem, log);
6868

6969
gitPreparer.Prepare(true, targetBranch);
@@ -97,7 +97,7 @@ public void CacheKeyForWorktree()
9797
TargetPath = worktreePath
9898
};
9999

100-
var gitPreparer = new GitPreparer(log, arguments);
100+
var gitPreparer = new GitPreparer(log, Options.Create(arguments));
101101
configFileLocator = new DefaultConfigFileLocator(fileSystem, log);
102102
var cacheKey = GitVersionCacheKeyFactory.Create(fileSystem, log, gitPreparer, configFileLocator, null);
103103
cacheKey.Value.ShouldNotBeEmpty();
@@ -212,7 +212,7 @@ public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDyn
212212
TargetPath = fixture.RepositoryPath
213213
};
214214

215-
var gitPreparer = new GitPreparer(log, arguments);
215+
var gitPreparer = new GitPreparer(log, Options.Create(arguments));
216216

217217
gitVersionCache = new GitVersionCache(fileSystem, log);
218218
var cacheDirectory = gitVersionCache.GetCacheDirectory(gitPreparer);
@@ -390,7 +390,7 @@ public void GetProjectRootDirectory_WorkingDirectoryWithWorktree()
390390
TargetPath = worktreePath
391391
};
392392

393-
var gitPreparer = new GitPreparer(log, arguments);
393+
var gitPreparer = new GitPreparer(log, Options.Create(arguments));
394394

395395
gitPreparer.GetProjectRootDirectory().TrimEnd('/', '\\').ShouldBe(worktreePath);
396396
}
@@ -414,7 +414,7 @@ public void GetProjectRootDirectory_NoWorktree()
414414
TargetPath = fixture.RepositoryPath
415415
};
416416

417-
var gitPreparer = new GitPreparer(log, arguments);
417+
var gitPreparer = new GitPreparer(log, Options.Create(arguments));
418418
var expectedPath = fixture.RepositoryPath.TrimEnd('/', '\\');
419419
gitPreparer.GetProjectRootDirectory().TrimEnd('/', '\\').ShouldBe(expectedPath);
420420
});
@@ -451,7 +451,7 @@ public void GetDotGitDirectory_NoWorktree()
451451
TargetPath = fixture.RepositoryPath
452452
};
453453

454-
var gitPreparer = new GitPreparer(log, arguments);
454+
var gitPreparer = new GitPreparer(log, Options.Create(arguments));
455455
var expectedPath = Path.Combine(fixture.RepositoryPath, ".git");
456456
gitPreparer.GetDotGitDirectory().ShouldBe(expectedPath);
457457
});
@@ -479,7 +479,7 @@ public void GetDotGitDirectory_Worktree()
479479
TargetPath = worktreePath
480480
};
481481

482-
var gitPreparer = new GitPreparer(log, arguments);
482+
var gitPreparer = new GitPreparer(log, Options.Create(arguments));
483483
var expectedPath = Path.Combine(fixture.RepositoryPath, ".git");
484484
gitPreparer.GetDotGitDirectory().ShouldBe(expectedPath);
485485
}
@@ -524,7 +524,7 @@ private void RepositoryScope(ILog _log, Action<EmptyRepositoryFixture, VersionVa
524524
var arguments = new Arguments { TargetPath = fixture.RepositoryPath };
525525
var options = Options.Create(arguments);
526526

527-
var gitPreparer = new GitPreparer(_log, arguments);
527+
var gitPreparer = new GitPreparer(_log, options);
528528
var stepFactory = new ConfigInitStepFactory();
529529
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
530530
var configurationProvider = new ConfigurationProvider(fileSystem, _log, configFileLocator, gitPreparer, configInitWizard);
@@ -547,7 +547,7 @@ private GitVersionCalculator GetGitVersionCalculator(Arguments arguments)
547547
{
548548
var options = Options.Create(arguments);
549549

550-
var gitPreparer = new GitPreparer(log, arguments);
550+
var gitPreparer = new GitPreparer(log, options);
551551
var stepFactory = new ConfigInitStepFactory();
552552
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
553553
var configurationProvider = new ConfigurationProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard);

src/GitVersionCore.Tests/Init/InitScenarios.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using GitVersion.Extensions;
88
using GitVersion.Logging;
99
using Microsoft.Extensions.DependencyInjection;
10+
using Microsoft.Extensions.Options;
1011
using NUnit.Framework;
1112
using Shouldly;
1213

@@ -44,7 +45,7 @@ public void CanSetNextVersion()
4445
var configFileLocator = new DefaultConfigFileLocator(fileSystem, log);
4546
var workingDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "c:\\proj" : "/proj";
4647

47-
var gitPreparer = new GitPreparer(log, new Arguments { TargetPath = workingDirectory });
48+
var gitPreparer = new GitPreparer(log, Options.Create(new Arguments { TargetPath = workingDirectory }));
4849
var configurationProvider = new ConfigurationProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard);
4950

5051
configurationProvider.Init(workingDirectory);

src/GitVersionCore.Tests/NamedConfigFileLocatorTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using GitVersion;
77
using GitVersion.Configuration.Init.Wizard;
88
using GitVersion.Logging;
9+
using Microsoft.Extensions.Options;
910

1011
namespace GitVersionCore.Tests
1112
{
@@ -60,7 +61,7 @@ public void NoWarnOnCustomYmlFile()
6061

6162
configFileLocator = new NamedConfigFileLocator("my-config.yaml", fileSystem, log);
6263

63-
var gitPreparer = new GitPreparer(log, new Arguments { TargetPath = repoPath });
64+
var gitPreparer = new GitPreparer(log, Options.Create(new Arguments { TargetPath = repoPath }));
6465
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
6566
var configurationProvider = new ConfigurationProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard);
6667

@@ -80,7 +81,7 @@ public void NoWarnOnCustomYmlFileOutsideRepoPath()
8081
log = new Log(logAppender);
8182

8283
configFileLocator = new NamedConfigFileLocator("my-config.yaml", fileSystem, log);
83-
var gitPreparer = new GitPreparer(log, new Arguments { TargetPath = repoPath });
84+
var gitPreparer = new GitPreparer(log, Options.Create(new Arguments { TargetPath = repoPath }));
8485
var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
8586
var configurationProvider = new ConfigurationProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard);
8687

src/GitVersionCore/GitPreparer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using GitVersion.Helpers;
55
using GitVersion.Logging;
66
using LibGit2Sharp;
7+
using Microsoft.Extensions.Options;
78

89
namespace GitVersion
910
{
@@ -17,9 +18,10 @@ public class GitPreparer : IGitPreparer
1718
private const string defaultRemoteName = "origin";
1819
private string dynamicGitRepositoryPath;
1920

20-
public GitPreparer(ILog log, Arguments arguments)
21+
public GitPreparer(ILog log, IOptions<Arguments> options)
2122
{
2223
this.log = log ?? throw new ArgumentNullException(nameof(log));
24+
var arguments = options.Value;
2325

2426
TargetUrl = arguments.TargetUrl;
2527
WorkingDirectory = arguments.TargetPath.TrimEnd('/', '\\');

src/GitVersionCore/GitVersionContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace GitVersion
1313
/// </summary>
1414
public class GitVersionContext
1515
{
16-
public ILog Log { get; set; }
16+
public ILog Log { get; }
1717

1818
public GitVersionContext(IRepository repository, ILog log, string targetBranch, Config configuration, bool onlyEvaluateTrackedBranches = true, string commitId = null)
1919
: this(repository, log, GetTargetBranch(repository, targetBranch), configuration, onlyEvaluateTrackedBranches, commitId)

src/GitVersionCore/GitVersionCoreModule.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public void RegisterTypes(IServiceCollection services)
3232
services.AddSingleton<IGitVersionCalculator, GitVersionCalculator>();
3333

3434
services.AddSingleton<IBuildServerResolver, BuildServerResolver>();
35+
services.AddSingleton<IGitPreparer, GitPreparer>();
3536

36-
services.AddSingleton(GetGitPreparer);
3737
services.AddSingleton(GetConfigFileLocator);
3838

3939
RegisterBuildServers(services);
@@ -56,14 +56,6 @@ private static IConfigFileLocator GetConfigFileLocator(IServiceProvider sp)
5656
return configFileLocator;
5757
}
5858

59-
private static IGitPreparer GetGitPreparer(IServiceProvider sp)
60-
{
61-
var log = sp.GetService<ILog>();
62-
var arguments = sp.GetService<IOptions<Arguments>>();
63-
64-
return new GitPreparer(log, arguments.Value);
65-
}
66-
6759
private static void RegisterBuildServers(IServiceCollection services)
6860
{
6961
services.AddSingleton<IBuildServer, ContinuaCi>();

0 commit comments

Comments
 (0)