Permalink
Browse files

Improve repo cache logic to clean up the cache instead of cloning

  • Loading branch information...
1 parent d269c81 commit 2f9bd16abd1280ec50c0c57f36db832b94e2c502 @davidebbo davidebbo committed Dec 1, 2012
@@ -52,7 +52,7 @@ public void DeploymentApis()
string cloneUrl = "https://github.com/KuduApps/HelloWorld.git";
string appName = KuduUtils.GetRandomWebsiteName("DeploymentApis");
- using (var repo = Git.Clone(repositoryName, cloneUrl, requiresEditableRepository: true))
+ using (var repo = Git.Clone(repositoryName, cloneUrl))
{
ApplicationManager.Run(appName, appManager =>
{
@@ -439,7 +439,7 @@ public void DeletesToRepositoryArePropagatedForNonWaps()
string repositoryName = "Bakery";
string cloneUrl = "https://github.com/KuduApps/Bakery.git";
string appName = KuduUtils.GetRandomWebsiteName("DeleteForNonWaps");
- using (var repo = Git.Clone(repositoryName, cloneUrl, requiresEditableRepository: true))
+ using (var repo = Git.Clone(repositoryName, cloneUrl))
{
ApplicationManager.Run(appName, appManager =>
{
@@ -575,7 +575,7 @@ public void CloneFromEmptyRepoAndPushShouldDeploy()
ApplicationManager.Run(appName, appManager =>
{
// Act
- using (var repo = Git.Clone(repositoryName, appManager.GitUrl, requiresEditableRepository: true))
+ using (var repo = Git.Clone(repositoryName, appManager.GitUrl))
{
// Add a file
repo.WriteFile("hello.txt", "Wow");
@@ -657,7 +657,7 @@ public void GoingBackInTimeDeploysOldFiles()
string repositoryName = "Bakery";
string cloneUrl = "https://github.com/KuduApps/Bakery.git";
string appName = KuduUtils.GetRandomWebsiteName("GoBackDeployOld");
- using (var repo = Git.Clone(repositoryName, cloneUrl, requiresEditableRepository: true))
+ using (var repo = Git.Clone(repositoryName, cloneUrl))
{
string originalCommitId = repo.CurrentId;
@@ -1106,14 +1106,14 @@ private void VerifyDeploymentConfiguration(string siteName, string targetProject
{
string name = KuduUtils.GetRandomWebsiteName(siteName);
string cloneUrl = "https://github.com/KuduApps/SpecificDeploymentConfiguration.git";
- using (var repo = Git.Clone(name, cloneUrl, requiresEditableRepository: true))
+ using (var repo = Git.Clone(name, cloneUrl))
{
ApplicationManager.Run(name, appManager =>
{
string deploymentFile = Path.Combine(repo.PhysicalPath, @".deployment");
File.WriteAllText(deploymentFile, String.Format(@"[config]
project = {0}", targetProject));
- Git.Commit(name, "Updated configuration");
+ Git.Commit(repo.PhysicalPath, "Updated configuration");
// Act
appManager.GitDeploy(repo.PhysicalPath);
@@ -13,15 +13,15 @@ public void NSimpleDeployments()
{
string repositoryName = "HelloKudu";
string cloneUrl = "https://github.com/KuduApps/HelloKudu.git";
- using (Git.Clone(repositoryName, cloneUrl))
+ using (var repo = Git.Clone(repositoryName, cloneUrl))
{
for (int i = 0; i < 5; i++)
{
string applicationName = KuduUtils.GetRandomWebsiteName(repositoryName + i);
ApplicationManager.Run(applicationName, appManager =>
{
// Act
- appManager.GitDeploy(repositoryName);
+ appManager.GitDeploy(repo.PhysicalPath);
var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
// Assert
View
@@ -84,17 +84,17 @@ public static void Add(string repositoryPath, string path)
gitExe.Execute("add \"{0}\"", path);
}
- public static TestRepository Clone(string repositoryName, string source, IDictionary<string, string> environments = null, bool requiresEditableRepository = false, bool noCache = false)
+ public static TestRepository Clone(string repositoryName, string source, IDictionary<string, string> environments = null, bool noCache = false)
{
- return OperationManager.Attempt(() => CloneInternal(repositoryName, source, environments, requiresEditableRepository, noCache));
+ return OperationManager.Attempt(() => CloneInternal(repositoryName, source, environments, noCache));
}
- private static TestRepository CloneInternal(string repositoryName, string source, IDictionary<string, string> environments, bool requiresEditableRepository, bool noCache)
+ private static TestRepository CloneInternal(string repositoryName, string source, IDictionary<string, string> environments, bool noCache)
{
// Check if we have a cached instance of the repository available locally
string cachedPath = noCache ? null : CreateCachedRepo(repositoryName, source, environments);
- if (cachedPath != null && !requiresEditableRepository)
+ if (cachedPath != null)
{
return new TestRepository(cachedPath, obliterateOnDispose: false);
}
@@ -110,23 +110,26 @@ private static TestRepository CloneInternal(string repositoryName, string source
private static string CreateCachedRepo(string repositoryName, string source, IDictionary<string, string> environments)
{
- Executable gitExe;
string cachedPath = null;
if (source.IndexOf("github.com", StringComparison.OrdinalIgnoreCase) != -1)
{
// If we're allowed to cache the repository, check if it already exists. If not clone it.
string repoName = Path.GetFileNameWithoutExtension(source.Split('/').Last());
cachedPath = Path.Combine(PathHelper.RepositoryCachePath, repoName);
+ Executable gitExe = GetGitExe(cachedPath, environments);
if (Directory.Exists(cachedPath))
{
Trace.WriteLine(String.Format("Using cached copy at location {0}", cachedPath));
+
+ // Get it into a clean state that matches a clean clone from github
+ gitExe.Execute("reset --hard origin/master");
+ gitExe.Execute("clean -dxf");
}
else
{
Trace.WriteLine(String.Format("Could not find a cached copy at {0}. Cloning from source {1}.", cachedPath, source));
PathHelper.EnsureDirectory(cachedPath);
- gitExe = GetGitExe(cachedPath, environments);
gitExe.Execute("clone \"{0}\" .", source);
}
}

0 comments on commit 2f9bd16

Please sign in to comment.