Пример #1
0
        public void MergeWith(ChorusHelper other)
        {
            var hgCommand = $"hg pull {other.RepoDir}";
            var result    = HgRunner.Run(hgCommand, RepoDir, 10, new NullProgress());

            if (result.ExitCode != 0)
            {
                throw new ApplicationException($"'{hgCommand}' returned {result.ExitCode}");
            }

            // Update to the revision we just pulled. This is necessary so that the notes
            // appears in the right order that we would get if we'd test manually
            hgCommand = "hg update tip";
            result    = HgRunner.Run(hgCommand, RepoDir, 10, new NullProgress());
            if (result.ExitCode != 0)
            {
                throw new ApplicationException($"'{hgCommand}' returned {result.ExitCode}");
            }

            Environment.SetEnvironmentVariable("ChorusPathToRepository", RepoDir);
            hgCommand = "hg merge -t chorusmerge";
            result    = HgRunner.Run(hgCommand, RepoDir, 10, new NullProgress());
            if (result.ExitCode != 0)
            {
                throw new ApplicationException($"'{hgCommand}' returned {result.ExitCode}");
            }

            hgCommand = "hg commit -m \"Merge\"";
            result    = HgRunner.Run(hgCommand, RepoDir, 10, new NullProgress());
            if (result.ExitCode != 0)
            {
                throw new ApplicationException($"'{hgCommand}' returned {result.ExitCode}");
            }
        }
Пример #2
0
        public void RemoveNodeFromFile(string fileName, string xpath, string commitMsg)
        {
            var fullFileName = Path.Combine(RepoDir, fileName);

            if (!File.Exists(fullFileName))
            {
                throw new FileNotFoundException("Can't find XML file", fullFileName);
            }

            var doc  = XDocument.Parse(File.ReadAllText(fullFileName));
            var node = doc.XPathSelectElement(xpath);

            if (node == null)
            {
                return;
            }

            node.Remove();
            doc.Save(fullFileName);

            HgRunner.Run($"hg add \"{fullFileName}\"", RepoDir, 10, new NullProgress());
            var hgCommand = $"hg commit --amend --message \"{commitMsg}\"";
            var result    = HgRunner.Run(hgCommand, RepoDir, 10, new NullProgress());

            if (result.ExitCode != 0)
            {
                throw new ApplicationException($"'{hgCommand}' returned {result.ExitCode}");
            }
        }
Пример #3
0
        /// <summary>
        /// Applies a patch to the mock hg repo
        /// </summary>
        /// <param name="patchFile">Patchfile and path, relative to <see cref="Settings.DataDir"/>.</param>
        /// <param name="commit"><c>true</c> to commit patch, <c>false</c> to just update the
        /// working directory.</param>
        /// <exception cref="FileNotFoundException">If <paramref name="patchFile"/> doesn't
        /// exist in <see cref="Settings.DataDir"/>.</exception>
        /// <exception cref="ApplicationException">If "hg import" returns a non-0 exit
        /// code</exception>
        private void ApplyPatch(string patchFile, bool commit = true)
        {
            var patchPath = Path.Combine(Settings.DataDir, patchFile);

            if (!File.Exists(patchPath))
            {
                throw new FileNotFoundException("Can't find patchfile", patchPath);
            }
            var commitArg = commit ? "" : "--no-commit";

            var command = $"hg import {commitArg} --import-branch {patchPath}";
            var result  = HgRunner.Run(command, RepoDir, 10, new NullProgress());

            if (result.ExitCode != 0)
            {
                throw new ApplicationException($"'{command}' returned {result.ExitCode}");
            }
        }
Пример #4
0
        public void ApplyReversePatch(string dbVersion, int patch, string commitMsg)
        {
            var patchPath = Path.Combine(Settings.DataDir, dbVersion, $"r{patch}.patch");

            if (!File.Exists(patchPath))
            {
                throw new FileNotFoundException("Can't find patchfile", patchPath);
            }

            TestHelper.Run(Patch, $"--reverse -p 1 -i {patchPath}", RepoDir);
            var hgCommand = $"hg commit --message \"{commitMsg}\"";
            var result    = HgRunner.Run(hgCommand, RepoDir, 10, new NullProgress());

            if (result.ExitCode != 0)
            {
                throw new ApplicationException($"'{hgCommand}' returned {result.ExitCode}");
            }
        }
Пример #5
0
        public void EnsureRepoIdIsCorrect()
        {
            using (var setup = new RepositorySetup("Dan"))
            {
                var id = setup.Repository.Identifier;
                Assert.IsTrue(String.IsNullOrEmpty(id));

                var path = setup.ProjectFolder.Combine("test.1w1");
                File.WriteAllText(path, "hello");
                setup.ProjectFolderConfig.IncludePatterns.Clear();
                setup.ProjectFolderConfig.ExcludePatterns.Clear();
                setup.ProjectFolderConfig.IncludePatterns.Add("*.1w1");
                setup.AddAndCheckIn();                 // Need to have one commit.

                id = setup.Repository.Identifier;
                Assert.IsFalse(String.IsNullOrEmpty(id));

                var results = HgRunner.Run("log -r0 --template " + "\"{node}\"", setup.Repository.PathToRepo, 10, setup.Progress);
                // This will probably fail, if some other version of Hg is used,
                // as it may include multiple lines (complaining about deprecated extension Chorus uses),
                // where the last one will be the id.
                Assert.AreEqual(results.StandardOutput.Trim(), id);
            }
        }
Пример #6
0
        private void RunSelected(string currentFwdataPathname)
        {
            _srcFwdataPathname = currentFwdataPathname;
            _workingDir        = Path.GetDirectoryName(_srcFwdataPathname);
            var sb                  = new StringBuilder();
            var sbValidation        = new StringBuilder();
            var nestTimer           = new Stopwatch();
            var breakupTimer        = new Stopwatch();
            var ambiguousTimer      = new Stopwatch();
            var restoreTimer        = new Stopwatch();
            var verifyTimer         = new Stopwatch();
            var checkOwnObjsurTimer = new Stopwatch();
            var validateTimer       = new Stopwatch();
            var danglingRefsTimer   = new Stopwatch();
            var ownObjsurFound      = false;

            try
            {
                if (_cbFindDanglingRefs.Checked)
                {
                    CheckForDanglingReferencesInMainFile(danglingRefsTimer, sb);
                }
                else if (_rebuildDataFile.Checked)
                {
                    if (!String.IsNullOrWhiteSpace(revisionBox.Text))
                    {
                        HgRunner.Run("hg update -r " + revisionBox.Text, _workingDir, 300, new NullProgress());
                    }
                    RestoreMainFileFromPieces(restoreTimer);
                }
                else
                {
                    RestoreProjectIfNeeded(_srcFwdataPathname);
                    if (_cbRoundTripData.Checked)
                    {
                        RoundTripData(breakupTimer, restoreTimer, ambiguousTimer, sbValidation);
                    }
                    if (_cbValidate.Checked)
                    {
                        ValidateSplitData(validateTimer, sb, sbValidation);
                    }
                    if (_cbVerify.Checked)
                    {
                        Verify(verifyTimer, sb);
                    }
                    if (_cbNestFile.Checked)
                    {
                        ownObjsurFound = NestFile(nestTimer, checkOwnObjsurTimer, _cbCheckOwnObjsur.Checked);
                    }
                }
            }
            catch (Exception err)
            {
                GC.Collect(2, GCCollectionMode.Forced);
                File.WriteAllText(Path.Combine(_workingDir, "StackTrace.log"),
                                  err.GetType().Name + Environment.NewLine + err.StackTrace);
                if (File.Exists(_srcFwdataPathname + ".orig"))
                {
                    File.Delete(_srcFwdataPathname);
                    File.Move(_srcFwdataPathname + ".orig", _srcFwdataPathname);                     // Restore it.
                }
            }
            finally
            {
                var compTxt = String.Format(
                    "Time to nest file: {1}{0}Time to check nested file: {2}{0}Own objsur Found: {3}{0}Time to breakup file: {4}.{0}Time to restore file: {5}.{0}Time to verify restoration: {6}.{0}Time to validate files: {7}.{0}Time to check ambiguous data: {8}.{0}Time to check dangling refs in main file: {9}.{0}{0}{10}",
                    Environment.NewLine,
                    nestTimer.ElapsedMilliseconds > 0 ? nestTimer.ElapsedMilliseconds.ToString(CultureInfo.InvariantCulture) : "Not run",
                    checkOwnObjsurTimer.ElapsedMilliseconds > 0
                                                ? checkOwnObjsurTimer.ElapsedMilliseconds.ToString(CultureInfo.InvariantCulture)
                                                : "Not run",
                    _cbCheckOwnObjsur.Checked ? (ownObjsurFound ? "********* YES FIX BUG *********" : "No") : "Not run",
                    breakupTimer.ElapsedMilliseconds > 0
                                                ? breakupTimer.ElapsedMilliseconds.ToString(CultureInfo.InvariantCulture)
                                                : "Not run",
                    restoreTimer.ElapsedMilliseconds > 0
                                                ? restoreTimer.ElapsedMilliseconds.ToString(CultureInfo.InvariantCulture)
                                                : "Not run",
                    verifyTimer.ElapsedMilliseconds > 0
                                                ? verifyTimer.ElapsedMilliseconds.ToString(CultureInfo.InvariantCulture)
                                                : "Not run",
                    validateTimer.ElapsedMilliseconds > 0
                                                ? validateTimer.ElapsedMilliseconds.ToString(CultureInfo.InvariantCulture)
                                                : "Not run",
                    ambiguousTimer.ElapsedMilliseconds > 0
                                                ? ambiguousTimer.ElapsedMilliseconds.ToString(CultureInfo.InvariantCulture)
                                                : "Not run",
                    danglingRefsTimer.ElapsedMilliseconds > 0
                                                ? danglingRefsTimer.ElapsedMilliseconds.ToString(CultureInfo.InvariantCulture)
                                                : "Not run",
                    sb);
                File.WriteAllText(Path.Combine(_workingDir, "Comparison.log"), compTxt);
                var validationErrors = sbValidation.ToString();
                if (validationErrors.Length > 0)
                {
                    File.WriteAllText(Path.Combine(_workingDir, "Validation.log"), validationErrors);
                }
            }
        }
Пример #7
0
        private static int GetTipRevision(string repoDir)
        {
            var result = HgRunner.Run("hg tip --template \"{rev}\"", repoDir, 10, new NullProgress());

            return(int.Parse(result.StandardOutput));
        }