3
3
using System . Text ;
4
4
using GitTools . Testing ;
5
5
using GitVersion ;
6
+ using GitVersion . BuildAgents ;
6
7
using GitVersion . Configuration ;
7
8
using GitVersion . Logging ;
8
9
using GitVersion . Model . Configuration ;
@@ -36,18 +37,23 @@ public void CacheKeySameAfterReNormalizing()
36
37
37
38
var gitVersionOptions = new GitVersionOptions
38
39
{
39
- RepositoryInfo = { TargetUrl = targetUrl } ,
40
- WorkingDirectory = fixture . RepositoryPath
40
+ RepositoryInfo = { TargetUrl = targetUrl , TargetBranch = targetBranch } ,
41
+ WorkingDirectory = fixture . RepositoryPath ,
42
+ Settings = { NoNormalize = false }
41
43
} ;
42
44
43
- sp = GetServiceProvider ( gitVersionOptions ) ;
45
+ var environment = new TestEnvironment ( ) ;
46
+ environment . SetEnvironmentVariable ( AzurePipelines . EnvironmentVariableName , "true" ) ;
44
47
45
- var preparer = sp . GetService < IGitPreparer > ( ) as GitPreparer ;
48
+ sp = GetServiceProvider ( gitVersionOptions , environment : environment ) ;
46
49
47
- preparer ? . PrepareInternal ( true , targetBranch ) ;
50
+ var preparer = sp . GetService < IGitPreparer > ( ) ;
51
+
52
+ preparer . Prepare ( ) ;
48
53
var cacheKeyFactory = sp . GetService < IGitVersionCacheKeyFactory > ( ) ;
49
54
var cacheKey1 = cacheKeyFactory . Create ( null ) ;
50
- preparer ? . PrepareInternal ( true , targetBranch ) ;
55
+ preparer . Prepare ( ) ;
56
+
51
57
var cacheKey2 = cacheKeyFactory . Create ( null ) ;
52
58
53
59
cacheKey2 . Value . ShouldBe ( cacheKey1 . Value ) ;
@@ -89,11 +95,14 @@ public void CacheKeyForWorktree()
89
95
90
96
var gitVersionOptions = new GitVersionOptions
91
97
{
92
- RepositoryInfo = { TargetUrl = targetUrl } ,
98
+ RepositoryInfo = { TargetUrl = targetUrl , TargetBranch = "master" } ,
93
99
WorkingDirectory = worktreePath
94
100
} ;
95
101
96
102
sp = GetServiceProvider ( gitVersionOptions ) ;
103
+
104
+ var preparer = sp . GetService < IGitPreparer > ( ) ;
105
+ preparer . Prepare ( ) ;
97
106
var cacheKey = sp . GetService < IGitVersionCacheKeyFactory > ( ) . Create ( null ) ;
98
107
cacheKey . Value . ShouldNotBeEmpty ( ) ;
99
108
}
@@ -460,11 +469,9 @@ public void DynamicRepositoriesShouldNotErrorWithFailedToFindGitDirectory()
460
469
public void GetDotGitDirectoryNoWorktree ( )
461
470
{
462
471
using var fixture = new EmptyRepositoryFixture ( ) ;
463
- var targetUrl = "https://github.com/GitTools/GitVersion.git" ;
464
472
465
473
var gitVersionOptions = new GitVersionOptions
466
474
{
467
- RepositoryInfo = { TargetUrl = targetUrl } ,
468
475
WorkingDirectory = fixture . RepositoryPath
469
476
} ;
470
477
@@ -489,11 +496,8 @@ public void GetDotGitDirectoryWorktree()
489
496
var repo = new Repository ( fixture . RepositoryPath ) ;
490
497
repo . Worktrees . Add ( "worktree" , worktreePath , false ) ;
491
498
492
- var targetUrl = "https://github.com/GitTools/GitVersion.git" ;
493
-
494
499
var gitVersionOptions = new GitVersionOptions
495
500
{
496
- RepositoryInfo = { TargetUrl = targetUrl } ,
497
501
WorkingDirectory = worktreePath
498
502
} ;
499
503
@@ -520,13 +524,14 @@ private IGitVersionTool GetGitVersionCalculator(GitVersionOptions gitVersionOpti
520
524
return sp . GetService < IGitVersionTool > ( ) ;
521
525
}
522
526
523
- private static IServiceProvider GetServiceProvider ( GitVersionOptions gitVersionOptions , ILog log = null , IRepository repository = null , IFileSystem fileSystem = null )
527
+ private static IServiceProvider GetServiceProvider ( GitVersionOptions gitVersionOptions , ILog log = null , IRepository repository = null , IFileSystem fileSystem = null , IEnvironment environment = null )
524
528
{
525
529
return ConfigureServices ( services =>
526
530
{
527
531
if ( log != null ) services . AddSingleton ( log ) ;
528
532
if ( fileSystem != null ) services . AddSingleton ( fileSystem ) ;
529
533
if ( repository != null ) services . AddSingleton ( repository ) ;
534
+ if ( environment != null ) services . AddSingleton ( environment ) ;
530
535
services . AddSingleton ( Options . Create ( gitVersionOptions ) ) ;
531
536
} ) ;
532
537
}
0 commit comments