Skip to content

Fix stale dynamic repo #425

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 3 commits into from
May 7, 2015
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
6 changes: 3 additions & 3 deletions GitVersionCore.Tests/GitVersionCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Shouldly, Version=2.4.0.0, Culture=neutral, PublicKeyToken=6042cbcb05cbc941, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Shouldly.2.4.0\lib\net40\Shouldly.dll</HintPath>
<Reference Include="Shouldly, Version=2.5.0.0, Culture=neutral, PublicKeyToken=6042cbcb05cbc941, processorArchitecture=MSIL">
<HintPath>..\packages\Shouldly.2.5.0\lib\net40\Shouldly.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
2 changes: 1 addition & 1 deletion GitVersionCore.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<package id="Fody" version="1.28.1" targetFramework="net45" developmentDependency="true" />
<package id="LibGit2Sharp" version="0.20.1.0" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="Shouldly" version="2.4.0" targetFramework="net45" />
<package id="Shouldly" version="2.5.0" targetFramework="net45" />
<package id="YamlDotNet" version="3.5.1" targetFramework="net45" />
</packages>
6 changes: 5 additions & 1 deletion GitVersionCore/BuildServers/GitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ public static class GitHelper
public static void NormalizeGitDirectory(string gitDirectory, Authentication authentication, bool noFetch)
{
//If noFetch is enabled, then GitVersion will assume that the git repository is normalized before execution, so that fetching from remotes is not required.
if (noFetch) return;
if (noFetch)
{
Logger.WriteInfo("Skipping fetching");
return;
}

using (var repo = new Repository(gitDirectory))
{
Expand Down
45 changes: 45 additions & 0 deletions GitVersionExe.Tests/GitPreparerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,51 @@ public void WorksCorrectlyWithRemoteRepository(string branchName, string expecte
}
}

[Test]
public void UpdatesExistingDynamicRepository()
{
var repoName = Guid.NewGuid().ToString();
var tempPath = Path.GetTempPath();
var tempDir = Path.Combine(tempPath, repoName);
Directory.CreateDirectory(tempDir);
string dynamicRepositoryPath = null;

try
{
using (var mainRepositoryFixture = new EmptyRepositoryFixture(new Config()))
{
mainRepositoryFixture.Repository.MakeCommits(1);

var arguments = new Arguments
{
TargetPath = tempDir,
TargetUrl = mainRepositoryFixture.RepositoryPath,
TargetBranch = "master"
};

var gitPreparer = new GitPreparer(arguments);
gitPreparer.InitialiseDynamicRepositoryIfNeeded();
dynamicRepositoryPath = gitPreparer.GetDotGitDirectory();

var newCommit = mainRepositoryFixture.Repository.MakeACommit();
gitPreparer.InitialiseDynamicRepositoryIfNeeded();

using (var repository = new Repository(dynamicRepositoryPath))
{
mainRepositoryFixture.DumpGraph();
repository.DumpGraph();
repository.Commits.ShouldContain(c => c.Sha == newCommit.Sha);
}
}
}
finally
{
Directory.Delete(tempDir, true);
if (dynamicRepositoryPath != null)
DeleteHelper.DeleteGitRepository(dynamicRepositoryPath);
}
}

[Test]
public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken()
{
Expand Down
6 changes: 3 additions & 3 deletions GitVersionExe.Tests/GitVersionExe.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Shouldly, Version=2.4.0.0, Culture=neutral, PublicKeyToken=6042cbcb05cbc941, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Shouldly.2.4.0\lib\net40\Shouldly.dll</HintPath>
<Reference Include="Shouldly, Version=2.5.0.0, Culture=neutral, PublicKeyToken=6042cbcb05cbc941, processorArchitecture=MSIL">
<HintPath>..\packages\Shouldly.2.5.0\lib\net40\Shouldly.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
2 changes: 1 addition & 1 deletion GitVersionExe.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
<package id="LibGit2Sharp" version="0.20.1.0" targetFramework="net45" />
<package id="NSubstitute" version="1.8.1.0" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="Shouldly" version="2.4.0" targetFramework="net45" />
<package id="Shouldly" version="2.5.0" targetFramework="net45" />
</packages>
15 changes: 13 additions & 2 deletions GitVersionExe/GitPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,19 @@ static string CreateDynamicRepository(string targetPath, Authentication authenti
var gitDirectory = Path.Combine(targetPath, ".git");
if (Directory.Exists(targetPath))
{
Logger.WriteInfo("Git repository already exists at {0}, skipping clone");
Logger.WriteInfo(string.Format("Git repository already exists at {0}", targetPath));
GitHelper.NormalizeGitDirectory(gitDirectory, authentication, noFetch);
Logger.WriteInfo(string.Format("Updating branch '{0}'", targetBranch));
using (var repo = new Repository(targetPath))
{
var targetGitBranch = repo.Branches[targetBranch];
var trackedBranch = targetGitBranch.TrackedBranch;
if (trackedBranch == null)
throw new InvalidOperationException(string.Format("Expecting {0} to have a remote tracking branch", targetBranch));

targetGitBranch.Checkout();
repo.Reset(ResetMode.Hard, trackedBranch.Tip);
}

return gitDirectory;
}
Expand All @@ -105,7 +117,6 @@ static string CreateDynamicRepository(string targetPath, Authentication authenti
Repository.Clone(repositoryUrl, gitDirectory,
new CloneOptions
{
IsBare = true,
Checkout = false,
CredentialsProvider = (url, usernameFromUrl, types) => credentials
});
Expand Down
6 changes: 3 additions & 3 deletions GitVersionTask.Tests/GitVersionTask.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\ObjectApproval.1.0.0\Lib\NET40\ObjectApproval.dll</HintPath>
</Reference>
<Reference Include="Shouldly, Version=2.4.0.0, Culture=neutral, PublicKeyToken=6042cbcb05cbc941, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Shouldly.2.4.0\lib\net40\Shouldly.dll</HintPath>
<Reference Include="Shouldly, Version=2.5.0.0, Culture=neutral, PublicKeyToken=6042cbcb05cbc941, processorArchitecture=MSIL">
<HintPath>..\packages\Shouldly.2.5.0\lib\net40\Shouldly.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable">
Expand Down
2 changes: 1 addition & 1 deletion GitVersionTask.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<package id="ModuleInit.Fody" version="1.5.6.0" targetFramework="net45" developmentDependency="true" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="ObjectApproval" version="1.0.0" targetFramework="net45" />
<package id="Shouldly" version="2.4.0" targetFramework="net45" />
<package id="Shouldly" version="2.5.0" targetFramework="net45" />
<package id="System.Collections.Immutable" version="1.1.32-beta" targetFramework="net45" />
<package id="System.Reflection.Metadata" version="1.0.17-beta" targetFramework="net45" />
</packages>