Example #1
0
        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 string GetLooseObjectPath(string fileGitPath, out string sha)
        {
            ProcessResult revParseResult = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, $"rev-parse :{fileGitPath}");

            sha = revParseResult.Output.Trim();
            sha.Length.ShouldEqual(40);
            string objectPath = Path.Combine(ScalarHelpers.GetObjectsRootFromGitConfig(this.Enlistment.RepoRoot), sha.Substring(0, 2), sha.Substring(2, 38));

            return(objectPath);
        }
        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);
        }
Example #5
0
        public void FetchStepCleansUpStaleFetchLock()
        {
            this.Enlistment.RunVerb("fetch");
            string fetchCommitsLockFile = Path.Combine(
                ScalarHelpers.GetObjectsRootFromGitConfig(this.Enlistment.RepoRoot),
                "pack",
                FetchCommitsAndTreesLock);

            fetchCommitsLockFile.ShouldNotExistOnDisk(this.fileSystem);
            this.fileSystem.WriteAllText(fetchCommitsLockFile, this.Enlistment.EnlistmentRoot);
            fetchCommitsLockFile.ShouldBeAFile(this.fileSystem);

            this.fileSystem
            .EnumerateDirectory(this.Enlistment.GetPackRoot(this.fileSystem))
            .Split()
            .Where(file => string.Equals(Path.GetExtension(file), ".keep", StringComparison.OrdinalIgnoreCase))
            .Count()
            .ShouldEqual(1, "Incorrect number of .keep files in pack directory");

            this.Enlistment.RunVerb("fetch");
            fetchCommitsLockFile.ShouldNotExistOnDisk(this.fileSystem);
        }