Example #1
0
        public void OpenFileThenCheckout()
        {
            string virtualFile = Path.Combine(this.Enlistment.RepoRoot, GitCommandsTests.EditFilePath);
            string controlFile = Path.Combine(this.ControlGitRepo.RootPath, GitCommandsTests.EditFilePath);

            // Open files with ReadWrite sharing because depending on the state of the index (and the mtimes), git might need to read the file
            // as part of status (while we have the handle open).
            using (FileStream virtualFS = File.Open(virtualFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite))
                using (StreamWriter virtualWriter = new StreamWriter(virtualFS))
                    using (FileStream controlFS = File.Open(controlFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite))
                        using (StreamWriter controlWriter = new StreamWriter(controlFS))
                        {
                            this.ValidateGitCommand("checkout -b tests/functional/OpenFileThenCheckout");
                            virtualWriter.WriteLine("// Adding a line for testing purposes");
                            controlWriter.WriteLine("// Adding a line for testing purposes");
                            this.ValidateGitCommand("status");
                        }

            // NOTE: Due to optimizations in checkout -b, the modified files will not be included as part of the
            // success message.  Validate that the succcess messages match, and the call to validate "status" below
            // will ensure that GVFS is still reporting the edited file as modified.

            string        controlRepoRoot = this.ControlGitRepo.RootPath;
            string        gvfsRepoRoot    = this.Enlistment.RepoRoot;
            string        command         = "checkout -b tests/functional/OpenFileThenCheckout_2";
            ProcessResult expectedResult  = GitProcess.InvokeProcess(controlRepoRoot, command);
            ProcessResult actualResult    = GitHelpers.InvokeGitAgainstGVFSRepo(gvfsRepoRoot, command);

            GitHelpers.ErrorsShouldMatch(command, expectedResult, actualResult);
            actualResult.Errors.ShouldContain("Switched to a new branch");

            this.ValidateGitCommand("status");
        }
Example #2
0
        /* We are using the following method for these scenarios
         * 1. Some commands compute a new commit sha, which is dependent on time and therefore
         *    won't match what is in the control repo.  For those commands, we just ensure that
         *    the errors match what we expect, but we skip comparing the output
         * 2. Using the sparse-checkout feature git will error out before checking the untracked files
         *    so the control repo will show the untracked files as being overwritten while the GVFS
         *    repo which is using the sparse-checkout will not.
         * 3. GVFS is returning not found for files that are outside the sparse-checkout and there
         *    are cases when git will delete these files during a merge outputting that it removed them
         *    which the GVFS repo did not have to remove so the message is missing that output.
         */
        protected void RunGitCommand(string command, bool ignoreErrors = false, bool checkStatus = true)
        {
            string controlRepoRoot = this.ControlGitRepo.RootPath;
            string gvfsRepoRoot    = this.Enlistment.RepoRoot;

            ProcessResult expectedResult = GitProcess.InvokeProcess(controlRepoRoot, command);
            ProcessResult actualResult   = GitHelpers.InvokeGitAgainstGVFSRepo(gvfsRepoRoot, command);

            if (!ignoreErrors)
            {
                GitHelpers.ErrorsShouldMatch(command, expectedResult, actualResult);
            }

            if (command != "status" && checkStatus)
            {
                this.ValidateGitCommand("status");
            }
        }