diff --git a/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/SharedCacheTests.cs b/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/SharedCacheTests.cs index 7ec39205a1..c7b3072f2a 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/SharedCacheTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/SharedCacheTests.cs @@ -21,7 +21,7 @@ public class SharedCacheTests : TestsWithMultiEnlistment // This branch and commit sha should point to the same place. private const string WellKnownBranch = "FunctionalTests/20170602"; - private const string WellKnownCommitSha = "79dc4233df4d9a7e053662bff95df498f640022e"; + private const string WellKnownCommitSha = "42eb6632beffae26893a3d6e1a9f48d652327c6f"; private string localCachePath; private string localCacheParentPath; @@ -268,6 +268,25 @@ public void MountUsesNewLocalCacheKeyWhenLocalCacheDeleted() this.AlternatesFileShouldHaveGitObjectsRoot(enlistment); } + [TestCase] + public void SecondCloneSucceedsWithMissingTrees() + { + string newCachePath = Path.Combine(this.localCacheParentPath, ".customGvfsCache2"); + GVFSFunctionalTestEnlistment enlistment1 = this.CreateNewEnlistment(localCacheRoot: newCachePath, skipPrefetch: true); + File.ReadAllText(Path.Combine(enlistment1.RepoRoot, WellKnownFile)); + this.AlternatesFileShouldHaveGitObjectsRoot(enlistment1); + + // This Git command loads the commit and root tree for WellKnownCommitSha, + // but does not download any more reachable objects. + string command = "cat-file -p origin/" + WellKnownBranch + "^{tree}"; + ProcessResult result = GitHelpers.InvokeGitAgainstGVFSRepo(enlistment1.RepoRoot, command); + result.ExitCode.ShouldEqual(0, $"git {command} failed with error: " + result.Errors); + + // If we did not properly check the failed checkout at this step, then clone will fail during checkout. + GVFSFunctionalTestEnlistment enlistment2 = this.CreateNewEnlistment(localCacheRoot: newCachePath, branch: WellKnownBranch, skipPrefetch: true); + File.ReadAllText(Path.Combine(enlistment2.RepoRoot, WellKnownFile)); + } + // Override OnTearDownEnlistmentsDeleted rathern than using [TearDown] as the enlistments need to be unmounted before // localCacheParentPath can be deleted (as the SQLite blob sizes database cannot be deleted while GVFS is mounted) protected override void OnTearDownEnlistmentsDeleted() diff --git a/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/TestsWithMultiEnlistment.cs b/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/TestsWithMultiEnlistment.cs index f0afd93995..3c9a353272 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/TestsWithMultiEnlistment.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/TestsWithMultiEnlistment.cs @@ -28,9 +28,16 @@ protected virtual void OnTearDownEnlistmentsDeleted() { } - protected GVFSFunctionalTestEnlistment CreateNewEnlistment(string localCacheRoot = null, string branch = null) + protected GVFSFunctionalTestEnlistment CreateNewEnlistment( + string localCacheRoot = null, + string branch = null, + bool skipPrefetch = false) { - GVFSFunctionalTestEnlistment output = GVFSFunctionalTestEnlistment.CloneAndMount(GVFSTestConfig.PathToGVFS, branch, localCacheRoot); + GVFSFunctionalTestEnlistment output = GVFSFunctionalTestEnlistment.CloneAndMount( + GVFSTestConfig.PathToGVFS, + branch, + localCacheRoot, + skipPrefetch); this.enlistmentsToDelete.Add(output); return output; } diff --git a/GVFS/GVFS.FunctionalTests/Tools/GVFSFunctionalTestEnlistment.cs b/GVFS/GVFS.FunctionalTests/Tools/GVFSFunctionalTestEnlistment.cs index 427fef7b28..eb6ea827cb 100644 --- a/GVFS/GVFS.FunctionalTests/Tools/GVFSFunctionalTestEnlistment.cs +++ b/GVFS/GVFS.FunctionalTests/Tools/GVFSFunctionalTestEnlistment.cs @@ -89,10 +89,14 @@ public static GVFSFunctionalTestEnlistment CloneAndMountWithPerRepoCache(string return CloneAndMount(pathToGvfs, enlistmentRoot, null, localCache, skipPrefetch); } - public static GVFSFunctionalTestEnlistment CloneAndMount(string pathToGvfs, string commitish = null, string localCacheRoot = null) + public static GVFSFunctionalTestEnlistment CloneAndMount( + string pathToGvfs, + string commitish = null, + string localCacheRoot = null, + bool skipPrefetch = false) { string enlistmentRoot = GVFSFunctionalTestEnlistment.GetUniqueEnlistmentRoot(); - return CloneAndMount(pathToGvfs, enlistmentRoot, commitish, localCacheRoot); + return CloneAndMount(pathToGvfs, enlistmentRoot, commitish, localCacheRoot, skipPrefetch); } public static GVFSFunctionalTestEnlistment CloneAndMountEnlistmentWithSpacesInPath(string pathToGvfs, string commitish = null)