Skip to content

Commit e4e3959

Browse files
Merge pull request #1073 from GitTools/feature/dynamic
#953 Fix dynamic repositories
2 parents 3a0765d + 5d9b736 commit e4e3959

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System.IO;
2+
using GitVersion;
3+
using NUnit.Framework;
4+
5+
[TestFixture]
6+
public class DynamicRepositoryTests
7+
{
8+
string workDirectory;
9+
10+
11+
[SetUp]
12+
public void CreateTemporaryRepository()
13+
{
14+
// Note: we can't use guid because paths will be too long
15+
workDirectory = Path.Combine(Path.GetTempPath(), "DynRepoTests");
16+
}
17+
18+
19+
//[TearDown]
20+
//public void Cleanup()
21+
//{
22+
// Directory.Delete(workDirectory, true);
23+
//}
24+
25+
[TestCase("GV_master_1", "https://github.com/GitTools/GitVersion", "master", "4783d325521463cd6cf1b61074352da84451f25d", "4.0.0+1126")]
26+
[TestCase("GV_master_2", "https://github.com/GitTools/GitVersion", "master", "3bdcd899530b4e9b37d13639f317da04a749e728", "4.0.0+1132")]
27+
public void FindsVersionInDynamicRepo(string name, string url, string targetBranch, string commitId, string expectedFullSemVer)
28+
{
29+
var root = Path.Combine(workDirectory, name);
30+
var dynamicDirectory = Path.Combine(root, "dynamic");
31+
var workingDirectory = Path.Combine(root, "working");
32+
33+
// Clear upfront
34+
if (Directory.Exists(root))
35+
{
36+
Directory.Delete(root, true);
37+
}
38+
39+
Directory.CreateDirectory(dynamicDirectory);
40+
Directory.CreateDirectory(workingDirectory);
41+
42+
var executeCore = new ExecuteCore(new TestFileSystem());
43+
44+
var versionVariables = executeCore.ExecuteGitVersion(url, dynamicDirectory, null, targetBranch,
45+
false, workingDirectory, commitId);
46+
47+
Assert.AreEqual(expectedFullSemVer, versionVariables.FullSemVer);
48+
}
49+
}

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
<Compile Include="BuildServers\VsoAgentTests.cs" />
121121
<Compile Include="BuildServers\TeamCityTests.cs" />
122122
<Compile Include="Configuration\IgnoreConfigTests.cs" />
123+
<Compile Include="DynamicRepositoryTests.cs" />
123124
<Compile Include="GitToolsTestingExtensions.cs" />
124125
<Compile Include="DocumentationTests.cs" />
125126
<Compile Include="ConfigProviderTests.cs" />

src/GitVersionCore/GitPreparer.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,19 @@ static string CreateDynamicRepository(string targetPath, AuthenticationInfo auth
166166
static void CloneRepository(string repositoryUrl, string gitDirectory, AuthenticationInfo authentication)
167167
{
168168
Credentials credentials = null;
169-
if (!string.IsNullOrWhiteSpace(authentication.Username) && !string.IsNullOrWhiteSpace(authentication.Password))
170-
{
171-
Logger.WriteInfo(string.Format("Setting up credentials using name '{0}'", authentication.Username));
172169

173-
credentials = new UsernamePasswordCredentials
170+
if (authentication != null)
171+
{
172+
if (!string.IsNullOrWhiteSpace(authentication.Username) && !string.IsNullOrWhiteSpace(authentication.Password))
174173
{
175-
Username = authentication.Username,
176-
Password = authentication.Password
177-
};
174+
Logger.WriteInfo(string.Format("Setting up credentials using name '{0}'", authentication.Username));
175+
176+
credentials = new UsernamePasswordCredentials
177+
{
178+
Username = authentication.Username,
179+
Password = authentication.Password
180+
};
181+
}
178182
}
179183

180184
Logger.WriteInfo(string.Format("Retrieving git info from url '{0}'", repositoryUrl));

0 commit comments

Comments
 (0)