public void CloneWithDefaultLocalCacheLocation() { FileSystemRunner fileSystem = FileSystemRunner.DefaultRunner; string homeDirectory = Environment.GetEnvironmentVariable("HOME"); homeDirectory.ShouldBeADirectory(fileSystem); string newEnlistmentRoot = ScalarFunctionalTestEnlistment.GetUniqueEnlistmentRoot(); ProcessStartInfo processInfo = new ProcessStartInfo(ScalarTestConfig.PathToScalar); processInfo.Arguments = $"clone {Properties.Settings.Default.RepoToClone} {newEnlistmentRoot} --no-fetch-commits-and-trees"; processInfo.WindowStyle = ProcessWindowStyle.Hidden; processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; processInfo.RedirectStandardOutput = true; processInfo.WorkingDirectory = Properties.Settings.Default.EnlistmentRoot; ProcessResult result = ProcessHelper.Run(processInfo); result.ExitCode.ShouldEqual(0, result.Errors); string gitObjectsRoot = ScalarHelpers.GetObjectsRootFromGitConfig(Path.Combine(newEnlistmentRoot, "src")); string defaultScalarCacheRoot = Path.Combine(homeDirectory, ".scalarCache"); gitObjectsRoot.StartsWith(defaultScalarCacheRoot, StringComparison.Ordinal).ShouldBeTrue($"Git objects root did not default to using {homeDirectory}"); RepositoryHelpers.DeleteTestDirectory(newEnlistmentRoot); }
private void AlternatesFileShouldHaveGitObjectsRoot(ScalarFunctionalTestEnlistment enlistment) { string objectsRoot = ScalarHelpers.GetObjectsRootFromGitConfig(enlistment.RepoRoot); string alternatesFileContents = Path.Combine(enlistment.RepoRoot, ".git", "objects", "info", "alternates").ShouldBeAFile(this.fileSystem).WithContents(); alternatesFileContents.ShouldEqual(objectsRoot); }
private void LoadBlobsViaGit(ScalarFunctionalTestEnlistment enlistment) { // 'git rev-list --objects' will check for all objects' existence, which // triggers an object download on every missing blob. ProcessResult result = GitHelpers.InvokeGitAgainstScalarRepo(enlistment.RepoRoot, "rev-list --all --objects"); result.ExitCode.ShouldEqual(0, result.Errors); }
public void DownloadingACommitWithoutTreesDoesntBreakNextClone() { ScalarFunctionalTestEnlistment enlistment1 = this.CloneEnlistment(); GitProcess.Invoke(enlistment1.RepoRoot, "cat-file -s " + WellKnownCommitSha).ShouldEqual("293\n"); ScalarFunctionalTestEnlistment enlistment2 = this.CloneEnlistment(WellKnownBranch); }
public void PartialCloneHttps() { ScalarFunctionalTestEnlistment enlistment = this.CreateNewEnlistment( url: MicrosoftScalarHttp, branch: "main", fullClone: false); VerifyPartialCloneBehavior(enlistment); }
protected void CreateEnlistment(string commitish = null) { this.Enlistment = ScalarFunctionalTestEnlistment.Clone( ScalarTestConfig.PathToScalar, commitish: commitish, fullClone: this.validateWorkingTree != Settings.ValidateWorkingTreeMode.SparseMode); GitProcess.Invoke(this.Enlistment.RepoRoot, "config advice.statusUoption false"); this.ControlGitRepo = ControlGitRepo.Create(commitish); this.ControlGitRepo.Initialize(); }
public void ServiceListRegistered() { ScalarFunctionalTestEnlistment enlistment1 = this.CreateNewEnlistment(); ScalarFunctionalTestEnlistment enlistment2 = this.CreateNewEnlistment(); string[] repoRootList = new string[] { enlistment1.EnlistmentRoot, enlistment2.EnlistmentRoot }; // Do not check for unexpected repos, as other repos on the machine may be registered while // this test is running this.RunListCommand(enlistment1.EnlistmentRoot, expectedRepoRoots: repoRootList); }
protected ScalarFunctionalTestEnlistment CreateNewEnlistment( string localCacheRoot = null, string branch = null, bool skipFetchCommitsAndTrees = false) { ScalarFunctionalTestEnlistment output = ScalarFunctionalTestEnlistment.Clone( ScalarTestConfig.PathToScalar, branch, localCacheRoot, skipFetchCommitsAndTrees); this.enlistmentsToDelete.Add(output); return output; }
public virtual void CreateEnlistment() { if (this.forcePerRepoObjectCache) { this.Enlistment = ScalarFunctionalTestEnlistment.CloneWithPerRepoCache( ScalarTestConfig.PathToScalar, this.skipFetchCommitsAndTreesDuringClone); } else { this.Enlistment = ScalarFunctionalTestEnlistment.Clone(ScalarTestConfig.PathToScalar, fullClone: this.fullClone); } }
public static void OutputScalarLogs(ScalarFunctionalTestEnlistment enlistment) { if (enlistment == null) { return; } Console.WriteLine("Scalar logs output attached below.\n\n"); foreach (string filename in GetAllFilesInDirectory(enlistment.ScalarLogsRoot)) { OutputFileContents(filename); } }
public void SparseCloneWithNoFetchOfCommitsAndTreesSucceeds() { ScalarFunctionalTestEnlistment enlistment = null; try { enlistment = ScalarFunctionalTestEnlistment.CloneWithPerRepoCache(ScalarTestConfig.PathToScalar, skipFetchCommitsAndTrees: true); ProcessResult result = GitProcess.InvokeProcess(enlistment.RepoRoot, "status"); result.ExitCode.ShouldEqual(0, result.Errors); } finally { enlistment?.DeleteAll(); } }
public void CloneCreatesCorrectFilesInRoot() { ScalarFunctionalTestEnlistment enlistment = ScalarFunctionalTestEnlistment.Clone(ScalarTestConfig.PathToScalar); try { Directory.GetFiles(enlistment.EnlistmentRoot).ShouldBeEmpty("There should be no files in the enlistment root after cloning"); string[] directories = Directory.GetDirectories(enlistment.EnlistmentRoot); directories.Length.ShouldEqual(1); directories.ShouldContain(x => Path.GetFileName(x).Equals("src", StringComparison.Ordinal)); } finally { enlistment.DeleteAll(); } }
public void CloneWithLocalCachePathWithinSrc() { string newEnlistmentRoot = ScalarFunctionalTestEnlistment.GetUniqueEnlistmentRoot(); ProcessStartInfo processInfo = new ProcessStartInfo(ScalarTestConfig.PathToScalar); processInfo.Arguments = $"clone {Properties.Settings.Default.RepoToClone} {newEnlistmentRoot} --local-cache-path {Path.Combine(newEnlistmentRoot, "src", ".scalarCache")}"; processInfo.WindowStyle = ProcessWindowStyle.Hidden; processInfo.CreateNoWindow = true; processInfo.WorkingDirectory = Path.GetDirectoryName(this.Enlistment.EnlistmentRoot); processInfo.UseShellExecute = false; processInfo.RedirectStandardOutput = true; ProcessResult result = ProcessHelper.Run(processInfo); result.ExitCode.ShouldEqual(ScalarGenericError); result.Output.ShouldContain("'--local-cache-path' cannot be inside the src folder"); }
private void VerifyPartialCloneBehavior(ScalarFunctionalTestEnlistment enlistment) { this.fileSystem.DirectoryExists(enlistment.RepoRoot).ShouldBeTrue($"'{enlistment.RepoRoot}' does not exist"); string gitPack = Path.Combine(enlistment.RepoRoot, ".git", "objects", "pack"); this.fileSystem.DirectoryExists(gitPack).ShouldBeTrue($"'{gitPack}' does not exist"); void checkPacks(string dir, int count, string when) { string dirContents = this.fileSystem .EnumerateDirectory(dir); dirContents .Split() .Where(file => string.Equals(Path.GetExtension(file), ".pack", StringComparison.OrdinalIgnoreCase)) .Count() .ShouldEqual(count, $"'{dir}' after '{when}': '{dirContents}'"); } // Two packs for clone: commits and trees, blobs at root checkPacks(gitPack, 2, "clone"); string srcScalar = Path.Combine(enlistment.RepoRoot, "Scalar"); this.fileSystem.DirectoryExists(srcScalar).ShouldBeFalse($"'{srcScalar}' should not exist due to sparse-checkout"); ProcessResult sparseCheckoutResult = GitProcess.InvokeProcess(enlistment.RepoRoot, "sparse-checkout disable"); sparseCheckoutResult.ExitCode.ShouldEqual(0, "git sparse-checkout disable exit code"); this.fileSystem.DirectoryExists(srcScalar).ShouldBeTrue($"'{srcScalar}' should exist after sparse-checkout"); // Three packs for sparse-chekcout: commits and trees, blobs at root, blobs outside root checkPacks(gitPack, 3, "sparse-checkout"); ProcessResult checkoutResult = GitProcess.InvokeProcess(enlistment.RepoRoot, "checkout HEAD~10"); checkoutResult.ExitCode.ShouldEqual(0, "git checkout exit code"); // Four packs for chekcout: commits and trees, blobs at root, blobs outside root, checkout diff checkPacks(gitPack, 4, "checkout"); }
public void UnregisterRemovesFromList() { ScalarFunctionalTestEnlistment enlistment1 = this.CreateNewEnlistment(); ScalarFunctionalTestEnlistment enlistment2 = this.CreateNewEnlistment(); string[] repoRootList = new string[] { enlistment1.EnlistmentRoot, enlistment2.EnlistmentRoot }; string workDir = Directory.GetCurrentDirectory(); this.RunListCommand(workDir, expectedRepoRoots: repoRootList); ScalarProcess process = new ScalarProcess(ScalarTestConfig.PathToScalar, "", ""); process.Unregister(enlistment1.EnlistmentRoot); this.RunListCommand( workDir, expectedRepoRoots: new[] { enlistment2.EnlistmentRoot }, unexpectedRepoRoots: new[] { enlistment1.EnlistmentRoot }); }
public void GitObjectsRecreatedWhenDownloadingObjects() { ScalarFunctionalTestEnlistment enlistment = this.CloneEnlistment(); // Find the current git objects root and ensure it's on disk string objectsRoot = ScalarHelpers.GetObjectsRootFromGitConfig(enlistment.RepoRoot); objectsRoot.ShouldBeADirectory(this.fileSystem); RepositoryHelpers.DeleteTestDirectory(objectsRoot); ScalarHelpers.GetObjectsRootFromGitConfig(enlistment.RepoRoot).ShouldEqual(objectsRoot); // Downloading objects should recreate the objects directory this.LoadBlobsViaGit(enlistment); objectsRoot.ShouldBeADirectory(this.fileSystem); // The alternates file shouldn't have changed this.AlternatesFileShouldHaveGitObjectsRoot(enlistment); }
public void ServiceListRegistered() { ScalarFunctionalTestEnlistment enlistment1 = this.CreateNewEnlistment(); ScalarFunctionalTestEnlistment enlistment2 = this.CreateNewEnlistment(); string[] repoRootList = new string[] { enlistment1.EnlistmentRoot, enlistment2.EnlistmentRoot }; ScalarProcess scalarProcess1 = new ScalarProcess( ScalarTestConfig.PathToScalar, enlistment1.EnlistmentRoot, enlistment1.LocalCacheRoot); ScalarProcess scalarProcess2 = new ScalarProcess( ScalarTestConfig.PathToScalar, enlistment2.EnlistmentRoot, enlistment2.LocalCacheRoot); // Do not check for unexpected repos, as other repos on the machine may be registered while // this test is running this.RunServiceCommandAndCheckOutput("--list-registered", expectedRepoRoots: repoRootList); }
public void SecondCloneSucceedsWithMissingTrees() { string newCachePath = Path.Combine(this.localCacheParentPath, ".customScalarCache2"); ScalarFunctionalTestEnlistment enlistment1 = this.CreateNewEnlistment(localCacheRoot: newCachePath, skipFetchCommitsAndTrees: 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.InvokeGitAgainstScalarRepo(enlistment1.RepoRoot, command); result.ExitCode.ShouldEqual(0, $"git {command} failed on {nameof(enlistment1)} with error: {result.Errors}"); // If we did not properly check the failed checkout at this step, then clone will fail during checkout. ScalarFunctionalTestEnlistment enlistment2 = this.CreateNewEnlistment(localCacheRoot: newCachePath, branch: WellKnownBranch, skipFetchCommitsAndTrees: true); result = GitHelpers.InvokeGitAgainstScalarRepo(enlistment2.RepoRoot, command); result.ExitCode.ShouldEqual(0, $"git {command} failed on {nameof(enlistment2)} with error: {result.Errors}"); }
public void ParallelDownloadsInSharedCache() { ScalarFunctionalTestEnlistment enlistment1 = this.CloneEnlistment(); ScalarFunctionalTestEnlistment enlistment2 = this.CloneEnlistment(); ScalarFunctionalTestEnlistment enlistment3 = null; Task task1 = Task.Run(() => this.LoadBlobsViaGit(enlistment1)); Task task2 = Task.Run(() => this.LoadBlobsViaGit(enlistment2)); Task task3 = Task.Run(() => enlistment3 = this.CloneEnlistment()); task1.Wait(); task2.Wait(); task3.Wait(); task1.Exception.ShouldBeNull(); task2.Exception.ShouldBeNull(); task3.Exception.ShouldBeNull(); this.AlternatesFileShouldHaveGitObjectsRoot(enlistment1); this.AlternatesFileShouldHaveGitObjectsRoot(enlistment2); this.AlternatesFileShouldHaveGitObjectsRoot(enlistment3); }
public void CloneToPathWithSpaces() { ScalarFunctionalTestEnlistment enlistment = ScalarFunctionalTestEnlistment.CloneEnlistmentWithSpacesInPath(ScalarTestConfig.PathToScalar); enlistment.DeleteAll(); }
public virtual void CreateRepo() { this.Enlistment = ScalarFunctionalTestEnlistment.CloneGitRepo(ScalarTestConfig.PathToScalar); }