Skip to content

Commit 90a22d4

Browse files
committed
Created test which verifies fix
1 parent 022f2c4 commit 90a22d4

File tree

6 files changed

+43
-13
lines changed

6 files changed

+43
-13
lines changed

GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
[TestFixture]
1414
public class ConfigProviderTests
1515
{
16-
string gitDirectory;
16+
string repoPath;
1717
IFileSystem fileSystem;
1818

1919
[SetUp]
2020
public void Setup()
2121
{
2222
fileSystem = new TestFileSystem();
23-
gitDirectory = "c:\\MyGitRepo\\.git";
23+
repoPath = "c:\\MyGitRepo";
2424
}
2525

2626
[Test]
@@ -41,7 +41,7 @@ public void CanReadDocument()
4141
";
4242
SetupConfigFileContent(text);
4343

44-
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
44+
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
4545
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
4646
config.NextVersion.ShouldBe("2.0.0");
4747
config.TagPrefix.ShouldBe("[vV|version-]");
@@ -61,7 +61,7 @@ public void CanReadOldDocument()
6161
release-branch-tag: rc
6262
";
6363
SetupConfigFileContent(text);
64-
var error = Should.Throw<OldConfigurationException>(() => ConfigurationProvider.Provide(gitDirectory, fileSystem));
64+
var error = Should.Throw<OldConfigurationException>(() => ConfigurationProvider.Provide(repoPath, fileSystem));
6565
error.Message.ShouldContainWithoutWhitespace(@"GitVersionConfig.yaml contains old configuration, please fix the following errors:
6666
assemblyVersioningScheme has been replaced by assembly-versioning-scheme
6767
develop-branch-tag has been replaced by branch specific configuration.See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration
@@ -79,7 +79,7 @@ public void OverwritesDefaultsWithProvidedConfig()
7979
tag: dev";
8080
SetupConfigFileContent(text);
8181
var defaultConfig = new Config();
82-
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
82+
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
8383

8484
config.NextVersion.ShouldBe("2.0.0");
8585
config.AssemblyVersioningScheme.ShouldBe(defaultConfig.AssemblyVersioningScheme);
@@ -97,7 +97,7 @@ public void CanProvideConfigForNewBranch()
9797
bug[/-]:
9898
tag: bugfix";
9999
SetupConfigFileContent(text);
100-
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
100+
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
101101

102102
config.Branches["bug[/-]"].Tag.ShouldBe("bugfix");
103103
}
@@ -106,7 +106,7 @@ public void CanProvideConfigForNewBranch()
106106
[MethodImpl(MethodImplOptions.NoInlining)]
107107
public void CanWriteOutEffectiveConfiguration()
108108
{
109-
var config = ConfigurationProvider.GetEffectiveConfigAsString(gitDirectory, fileSystem);
109+
var config = ConfigurationProvider.GetEffectiveConfigAsString(repoPath, fileSystem);
110110

111111
Approvals.Verify(config);
112112
}
@@ -116,7 +116,7 @@ public void CanReadDefaultDocument()
116116
{
117117
const string text = "";
118118
SetupConfigFileContent(text);
119-
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
119+
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
120120
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
121121
config.Branches["develop"].Tag.ShouldBe("unstable");
122122
config.Branches["release[/-]"].Tag.ShouldBe("beta");
@@ -156,6 +156,6 @@ public void VerifyAliases()
156156

157157
void SetupConfigFileContent(string text)
158158
{
159-
fileSystem.WriteAllText(Path.Combine(Directory.GetParent(gitDirectory).FullName, "GitVersionConfig.yaml"), text);
159+
fileSystem.WriteAllText(Path.Combine(repoPath, "GitVersionConfig.yaml"), text);
160160
}
161161
}

GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static void WriteSample(string workingDirectory, IFileSystem fileSystem)
5353

5454
static string GetConfigFilePath(string workingDirectory)
5555
{
56-
return Path.Combine(Directory.GetParent(workingDirectory).FullName, "GitVersionConfig.yaml");
56+
return Path.Combine(workingDirectory, "GitVersionConfig.yaml");
5757
}
5858
}
5959
}

GitVersionCore/ExecuteCore.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public static VersionVariables ExecuteGitVersion(IFileSystem fileSystem, string
1414
gitPreparer.Initialise();
1515
var dotGitDirectory = gitPreparer.GetDotGitDirectory();
1616
var projectRoot = gitPreparer.GetProjectRootDirectory();
17+
Logger.WriteInfo(string.Format("Project root is: " + projectRoot));
1718
if (string.IsNullOrEmpty(dotGitDirectory) || string.IsNullOrEmpty(projectRoot))
1819
{
1920
// TODO Link to wiki article

GitVersionExe.Tests/ArgumentBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ public ArgumentBuilder(string workingDirectory, string exec, string execArgs, st
1919
this.isTeamCity = isTeamCity;
2020
}
2121

22-
public ArgumentBuilder(string workingDirectory, string additionalArguments, bool isTeamCity)
22+
public ArgumentBuilder(string workingDirectory, string additionalArguments, bool isTeamCity, string logFile)
2323
{
2424
this.workingDirectory = workingDirectory;
2525
this.isTeamCity = isTeamCity;
2626
this.additionalArguments = additionalArguments;
27+
this.logFile = logFile;
2728
}
2829

2930

GitVersionExe.Tests/GitPreparerTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,32 @@ public void WorksCorrectlyWithLocalRepository()
181181
gitPreparer.IsDynamicGitRepository.ShouldBe(false);
182182
}
183183

184+
[Test]
185+
public void UsesGitVersionConfigWhenCreatingDynamicRepository()
186+
{
187+
string localRepoPath = PathHelper.GetTempPath();
188+
string repoBasePath = Path.GetDirectoryName(PathHelper.GetTempPath());
189+
Directory.CreateDirectory(localRepoPath);
190+
191+
try
192+
{
193+
using (var remote = new EmptyRepositoryFixture(new Config()))
194+
{
195+
remote.Repository.MakeACommit();
196+
var configFile = Path.Combine(localRepoPath, "GitVersionConfig.yaml");
197+
File.WriteAllText(configFile, "next-version: 1.0.0");
198+
199+
var arguments = string.Format(" /url {0} /dynamicRepoLocation {1}", remote.RepositoryPath, repoBasePath);
200+
var results = GitVersionHelper.ExecuteIn(localRepoPath, arguments, false);
201+
results.OutputVariables.SemVer.ShouldBe("1.0.0");
202+
}
203+
}
204+
finally
205+
{
206+
DeleteHelper.DeleteGitRepository(localRepoPath);
207+
DeleteHelper.DeleteGitRepository(repoBasePath);
208+
}
209+
}
210+
184211
// TODO test around normalisation
185212
}

GitVersionExe.Tests/GitVersionHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public static ExecutionResults ExecuteIn(string workingDirectory,
1717

1818
public static ExecutionResults ExecuteIn(string workingDirectory, string arguments, bool isTeamCity = false)
1919
{
20-
var args = new ArgumentBuilder(workingDirectory, arguments, isTeamCity);
20+
var logFile = Path.Combine(workingDirectory, "log.txt");
21+
var args = new ArgumentBuilder(workingDirectory, arguments, isTeamCity, logFile);
2122
return ExecuteIn(args);
2223
}
2324

@@ -46,7 +47,7 @@ static ExecutionResults ExecuteIn(ArgumentBuilder arguments)
4647
Console.WriteLine();
4748
Console.WriteLine("-------------------------------------------------------");
4849

49-
if (string.IsNullOrWhiteSpace(arguments.LogFile))
50+
if (string.IsNullOrWhiteSpace(arguments.LogFile) || !File.Exists(arguments.LogFile))
5051
{
5152
return new ExecutionResults(exitCode, output.ToString(), null);
5253
}

0 commit comments

Comments
 (0)