Skip to content

Fixed issue where config is no longer discovered #763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GitVersionConfig.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
assembly-versioning-scheme: MajorMinorPatch
next-version: 3.1.0
next-version: 3.4.0
17 changes: 11 additions & 6 deletions src/GitVersionCore.Tests/GitPreparerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,17 @@ public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken()
[Test]
public void WorksCorrectlyWithLocalRepository()
{
var tempDir = Path.GetTempPath();
var gitPreparer = new GitPreparer(null, null, null, false, tempDir);
var dynamicRepositoryPath = gitPreparer.GetDotGitDirectory();

dynamicRepositoryPath.ShouldBe(null);
gitPreparer.IsDynamicGitRepository.ShouldBe(false);
using (var fixture = new EmptyRepositoryFixture(new Config()))
{
var targetPath = Path.Combine(fixture.RepositoryPath, "tools\\gitversion\\");
Directory.CreateDirectory(targetPath);
var gitPreparer = new GitPreparer(null, null, null, false, targetPath);
var dotGitDirectory = gitPreparer.GetDotGitDirectory();
var projectRoot = gitPreparer.GetProjectRootDirectory();

dotGitDirectory.ShouldBe(Path.Combine(fixture.RepositoryPath, ".git"));
projectRoot.ShouldBe(fixture.RepositoryPath);
}
}

[Test]
Expand Down
17 changes: 7 additions & 10 deletions src/GitVersionCore/GitPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public GitPreparer(string targetUrl, string dynamicRepositoryLocation, Authentic
this.dynamicRepositoryLocation = dynamicRepositoryLocation;
this.authentication = authentication;
this.noFetch = noFetch;
this.targetPath = targetPath;
this.targetPath = targetPath.TrimEnd('/', '\\');
}

public bool IsDynamicGitRepository
Expand Down Expand Up @@ -89,24 +89,21 @@ static bool GitRepoHasMatchingRemote(string possiblePath, string targetUrl)
public string GetDotGitDirectory()
{
if (IsDynamicGitRepository)
{
return DynamicGitRepositoryPath;
}

return Repository.Discover(targetPath);
var dotGitDirectory = Repository.Discover(targetPath).TrimEnd('/', '\\');
if (string.IsNullOrEmpty(dotGitDirectory))
throw new DirectoryNotFoundException("Can't find the .git directory in " + targetPath);

return dotGitDirectory;
}

public string GetProjectRootDirectory()
{
if (IsDynamicGitRepository)
return targetPath;

var gitDir = Repository.Discover(targetPath);

if (string.IsNullOrEmpty(gitDir))
throw new DirectoryNotFoundException("Can't find the .git directory in " + targetPath);

return Directory.GetParent(gitDir).FullName;
return Directory.GetParent(GetDotGitDirectory()).FullName;
}

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