Skip to content

Commit c99b6ba

Browse files
committed
Merge pull request #763 from JakeGinnivan/FixedConfigDiscovery
Fixed issue where config is no longer discovered
2 parents d6289ba + 2a8e26f commit c99b6ba

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

GitVersionConfig.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
assembly-versioning-scheme: MajorMinorPatch
2-
next-version: 3.1.0
2+
next-version: 3.4.0

src/GitVersionCore.Tests/GitPreparerTests.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,17 @@ public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken()
136136
[Test]
137137
public void WorksCorrectlyWithLocalRepository()
138138
{
139-
var tempDir = Path.GetTempPath();
140-
var gitPreparer = new GitPreparer(null, null, null, false, tempDir);
141-
var dynamicRepositoryPath = gitPreparer.GetDotGitDirectory();
142-
143-
dynamicRepositoryPath.ShouldBe(null);
144-
gitPreparer.IsDynamicGitRepository.ShouldBe(false);
139+
using (var fixture = new EmptyRepositoryFixture(new Config()))
140+
{
141+
var targetPath = Path.Combine(fixture.RepositoryPath, "tools\\gitversion\\");
142+
Directory.CreateDirectory(targetPath);
143+
var gitPreparer = new GitPreparer(null, null, null, false, targetPath);
144+
var dotGitDirectory = gitPreparer.GetDotGitDirectory();
145+
var projectRoot = gitPreparer.GetProjectRootDirectory();
146+
147+
dotGitDirectory.ShouldBe(Path.Combine(fixture.RepositoryPath, ".git"));
148+
projectRoot.ShouldBe(fixture.RepositoryPath);
149+
}
145150
}
146151

147152
[Test]

src/GitVersionCore/GitPreparer.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public GitPreparer(string targetUrl, string dynamicRepositoryLocation, Authentic
2020
this.dynamicRepositoryLocation = dynamicRepositoryLocation;
2121
this.authentication = authentication;
2222
this.noFetch = noFetch;
23-
this.targetPath = targetPath;
23+
this.targetPath = targetPath.TrimEnd('/', '\\');
2424
}
2525

2626
public bool IsDynamicGitRepository
@@ -89,24 +89,21 @@ static bool GitRepoHasMatchingRemote(string possiblePath, string targetUrl)
8989
public string GetDotGitDirectory()
9090
{
9191
if (IsDynamicGitRepository)
92-
{
9392
return DynamicGitRepositoryPath;
94-
}
9593

96-
return Repository.Discover(targetPath);
94+
var dotGitDirectory = Repository.Discover(targetPath).TrimEnd('/', '\\');
95+
if (string.IsNullOrEmpty(dotGitDirectory))
96+
throw new DirectoryNotFoundException("Can't find the .git directory in " + targetPath);
97+
98+
return dotGitDirectory;
9799
}
98100

99101
public string GetProjectRootDirectory()
100102
{
101103
if (IsDynamicGitRepository)
102104
return targetPath;
103105

104-
var gitDir = Repository.Discover(targetPath);
105-
106-
if (string.IsNullOrEmpty(gitDir))
107-
throw new DirectoryNotFoundException("Can't find the .git directory in " + targetPath);
108-
109-
return Directory.GetParent(gitDir).FullName;
106+
return Directory.GetParent(GetDotGitDirectory()).FullName;
110107
}
111108

112109
static string CreateDynamicRepository(string targetPath, Authentication authentication, string repositoryUrl, string targetBranch, bool noFetch)

0 commit comments

Comments
 (0)