Exemple #1
0
        public void LaunchDialog_SimulatedUsb_ProjectAlreadyExists()
        {
            using (var targetComputer = new TemporaryFolder("clonetest-targetComputer"))
                using (var usb = new TemporaryFolder("clonetest-Usb"))
                {
                    Directory.CreateDirectory(usb.Combine("repo1"));
                    HgRepository.CreateRepositoryInExistingDir(usb.Combine("repo1"), new NullProgress());

                    //ok, the point here is that we already haved something called "repo1"
                    Directory.CreateDirectory(targetComputer.Combine("repo1"));

                    using (var dlg = new GetCloneFromUsbDialog(targetComputer.Path))
                    {
                        var drives = new List <IUsbDriveInfo>();
                        drives.Add(new UsbDriveInfoForTests(usb.Path));

                        //don't look at the actual drives, look at our simulations
                        dlg.Model.DriveInfoRetriever = new RetrieveUsbDriveInfoForTests(drives);

                        if (DialogResult.OK != dlg.ShowDialog())
                        {
                            return;
                        }
                    }
                }
        }
Exemple #2
0
 public void MakeListItemWhenAlreadyHaveProjectName_MakesDisabledItem()
 {
     using (var usb = new TemporaryFolder("clonetestUsb"))
     {
         var path = usb.Combine("test1");
         Directory.CreateDirectory(path);
         var testFile = Path.Combine(path, "test.file");
         File.WriteAllText(testFile, @"exist");
         var repo = HgRepository.CreateRepositoryInExistingDir(path, new NullProgress());
         repo.AddAndCheckinFile(testFile);
         var model = new CloneFromUsb {
             ExistingProjects = new HashSet <string> {
                 "test1"
             }
         };
         var item = model.CreateListItemFor(path);
         Assert.That(item, Is.Not.Null, "model should have made a list item");
         Assert.That(item.Text, Is.EqualTo("test1"));
         Assert.That(item.Tag, Is.EqualTo(path));
         var last            = File.GetLastWriteTime(path);
         var expectedSubitem = last.ToShortDateString() + " " + last.ToShortTimeString();
         // Not a great test, basically duplicates the impl
         Assert.That(item.SubItems[1].Text, Is.EqualTo(expectedSubitem));
         Assert.That(item.ToolTipText, Is.EqualTo(CloneFromUsb.ProjectWithSameNameExists));
         Assert.That(item.ImageIndex, Is.EqualTo(2));
         Assert.That(item.ForeColor, Is.EqualTo(CloneFromUsb.DisabledItemForeColor));
     }
 }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="id"></param>
        /// <returns>true if client should wait for hg to notice</returns>
        public bool PrepareToReceiveRepository(string name, string id)
        {
            if (!string.IsNullOrEmpty(id))
            {
                var jsonStrings = GetRepositoryInformation(string.Empty);
                var hubInfo     = ImitationHubJSONService.ParseJsonStringsToChorusHubRepoInfos(jsonStrings);
                if (hubInfo.Any(info => info.RepoID == id))
                {
                    return(false);
                }
            }

            // since the repository doesn't exist, create it
            var directory = Path.Combine(ChorusHubOptions.RootDirectory, name);
            var uniqueDir = DirectoryUtilities.GetUniqueFolderPath(directory);

            //EventLog.WriteEntry("Application", string.Format("PrepareToReceiveRepository() is preparing a place for '{0}'.", name), EventLogEntryType.Information);
            if (uniqueDir != directory)
            {
                //EventLog.WriteEntry("Application", string.Format("{0} already exists! Creating repository for {1} at {2}.", directory, name, uniqueDir), EventLogEntryType.Warning);
            }
            Directory.CreateDirectory(uniqueDir);
            HgRepository.CreateRepositoryInExistingDir(uniqueDir, new ConsoleProgress());
            return(true);
        }
Exemple #4
0
 public void GetRevision_WithTwoCommits_HasExpectedRevisionValuesForSecondCommit()
 {
     using (var testRoot = new TemporaryFolder("RepositoryTests"))
     {
         HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress);
         var repo = new HgRepository(testRoot.Path, new NullProgress());
         Assert.That(repo.Identifier, Is.Null);
         var rev = repo.GetAllRevisions().FirstOrDefault();
         Assert.That(rev, Is.Null);
         using (var file1 = testRoot.GetNewTempFile(true))
         {
             repo.AddAndCheckinFile(file1.Path);
             using (var file2 = testRoot.GetNewTempFile(true))
             {
                 repo.AddAndCheckinFile(file2.Path);
                 rev = repo.GetRevisionWorkingSetIsBasedOn();
                 Assert.That(rev.Number.LocalRevisionNumber, Is.EqualTo("1"));
                 Assert.That(rev.Number.Hash.Length, Is.EqualTo(12));
                 Assert.That(rev.Number.Hash, Is.EqualTo(rev.Number.LongHash.Substring(0, 12)));
                 // We can't test for the value of rev.Number.LongHash,
                 // since Mercurial makes up a unique hash,
                 // that is not knowable ahead of time.
             }
         }
     }
 }
Exemple #5
0
 public HgTestSetup()
 {
     _progress = new ConsoleProgress();
     Root      = new TemporaryFolder("ChorusHgWrappingTest");
     HgRepository.CreateRepositoryInExistingDir(Root.Path, _progress);
     Repository = new HgRepository(Root.Path, new NullProgress());
 }
Exemple #6
0
 public void LaunchDialog_CustomUrlSourceWontBeFound()        //gives HTTP Error 404: Not Found
 {
     using (var source = new TemporaryFolder("CloneDialogTest"))
     {
         Directory.CreateDirectory(source.Combine("repo1"));
         HgRepository.CreateRepositoryInExistingDir(source.Combine("repo1"), new NullProgress());
         LaunchCustomUrl(@"somewhereElse");
     }
 }
Exemple #7
0
 public void LaunchDialog_CustomSourceWillBeFound()
 {
     using (var source = new TemporaryFolder("CloneDialogTest"))
     {
         Directory.CreateDirectory(source.Combine("repo1"));
         HgRepository.CreateRepositoryInExistingDir(source.Combine("repo1"), new NullProgress());
         LaunchCustomUrl(source.Combine("repo1"));
     }
 }
Exemple #8
0
 public void UpdateToLongHashOnEmptyRepoReturns_UpdateResults_NoCommitsInRepository()
 {
     using (var testRoot = new TemporaryFolder("RepositoryTests"))
     {
         HgRepository.CreateRepositoryInExistingDir(testRoot.Path, new NullProgress());
         var repo = new HgRepository(testRoot.Path, new NullProgress());
         Assert.That(repo.UpdateToLongHash("fakelonghash"), Is.EqualTo(HgRepository.UpdateResults.NoCommitsInRepository));
     }
 }
Exemple #9
0
 public void BadMercurialIni_Throws()
 {
     using (new MercurialIniHider())
         using (var testRoot = new TemporaryFolder("ChorusHgSettingsTest"))
         {
             Assert.Throws <ApplicationException>(() =>
                                                  HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress)
                                                  );
         }
 }
Exemple #10
0
 public void GetRevisionWorkingSetIsBasedOn_NoCheckinsYet_GivesNull()
 {
     using (var testRoot = new TemporaryFolder("ChorusHgWrappingTest"))
     {
         HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress);
         var repo = new HgRepository(testRoot.Path, new NullProgress());
         var rev  = repo.GetRevisionWorkingSetIsBasedOn();
         Assert.IsNull(rev);
     }
 }
Exemple #11
0
        public void CheckForFailedPushes()
        {
            try
            {
                if (!File.Exists(AccessLogPath))
                {
                    return;
                }

                using (var stream = File.Open(AccessLogPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    using (TextReader reader = new StreamReader(stream))
                    {
                        while (true)
                        {
                            try
                            {
                                var line = reader.ReadLine();
                                if (line == null)
                                {
                                    return;
                                }

                                var start = line.IndexOf("GET /") + 5;
                                var end   = line.IndexOf("?");
                                if (line.Contains("404") && start > 9 & end > 0)
                                {
                                    var    name      = line.Substring(start, end - start);
                                    string directory = Path.Combine(_rootFolder, name);

                                    directory = SIL.Network.HttpUtilityFromMono.UrlDecode(directory);                             // convert %20 --> space
                                    if (!Directory.Exists(directory))
                                    {
                                        //Progress.WriteMessage("Creating new folder '" + name + "'");
                                        Directory.CreateDirectory(directory);
                                    }
                                    if (!Directory.Exists(Path.Combine(directory, ".hg")))
                                    {
                                        //Progress.WriteMessage("Initializing blank repository: " + name +
                                        //				  ". Try Sending again in a few minutes, when hg notices the new directory.");
                                        HgRepository.CreateRepositoryInExistingDir(directory, new ConsoleProgress());
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }
                    }
            }
            catch (Exception error)
            {
                //EventLog.WriteEntry("Application", error.Message, EventLogEntryType.Error);
            }
        }
Exemple #12
0
 [Test] public void GetKnownRepositories_NoneKnown_GivesNone()
 {
     using (new MercurialIniForTests())
         using (var testRoot = new TemporaryFolder("ChorusHgSettingsTest"))
         {
             HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress);
             var repo    = new HgRepository(testRoot.Path, _progress);
             var sources = repo.GetRepositoryPathsInHgrc();
             Assert.AreEqual(0, sources.Count());
         }
 }
Exemple #13
0
 public void GetRevisionWorkingSetIsBasedOn_OneCheckin_Gives0()
 {
     using (var testRoot = new TemporaryFolder("ChorusHgWrappingTest"))
     {
         HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress);
         var repo = new HgRepository(testRoot.Path, new NullProgress());
         using (var f = testRoot.GetNewTempFile(true))
         {
             repo.AddAndCheckinFile(f.Path);
             var rev = repo.GetRevisionWorkingSetIsBasedOn();
             Assert.AreEqual("0", rev.Number.LocalRevisionNumber);
             Assert.AreEqual(12, rev.Number.Hash.Length);
         }
     }
 }
Exemple #14
0
        private bool GetIsReady(string pathsSectionContents)
        {
            string contents = @"[paths]" + Environment.NewLine + pathsSectionContents + Environment.NewLine;

            using (var testRoot = new TemporaryFolder("ChorusHgSettingsTest"))
            {
                HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress);
                File.WriteAllText(testRoot.Combine(Path.Combine(".hg", "hgrc")), contents);
                var    repo = new HgRepository(testRoot.Path, _progress);
                string msg;
                bool   ready = repo.GetIsReadyForInternetSendReceive(out msg);
                Console.WriteLine(msg);
                return(ready);
            }
        }
Exemple #15
0
        private void Launch()
        {
            using (var targetComputer = new TemporaryFolder("clonetest-targetComputer"))
                using (var dest = new TemporaryFolder("clonetest"))
                {
                    Directory.CreateDirectory(dest.Combine("repo1"));
                    HgRepository.CreateRepositoryInExistingDir(dest.Combine("repo1"), new NullProgress());

                    //ok, the point here is that we already haved something called "repo1"
                    Directory.CreateDirectory(targetComputer.Combine("repo1"));

                    using (var dlg = new GetCloneFromInternetDialog(targetComputer.Path))
                    {
                        dlg.ShowDialog();
                    }
                }
        }
Exemple #16
0
        public void UpdateToLongHashOnNonExistantLongHashReturns_UpdateResults_NoSuchRevision()
        {
            using (var testRoot = new TemporaryFolder("RepositoryTests"))
            {
                var progress = new NullProgress();
                HgRepository.CreateRepositoryInExistingDir(testRoot.Path, progress);
                // fileX and fileXRev are zero based indexing, since those local commit numbers in Hg are zero based indexing.
                using (var file0 = testRoot.GetNewTempFile(true))
                {
                    var repo = new HgRepository(testRoot.Path, new NullProgress());
                    repo.AddAndCheckinFile(file0.Path);

                    // SUT
                    Assert.That(repo.UpdateToLongHash("12345678901234567890BAD0HASH000000000000"), Is.EqualTo(HgRepository.UpdateResults.NoSuchRevision));
                }
            }
        }
Exemple #17
0
        public void UpdateToLongHashOnSameLongHashReturns_UpdateResults_AlreadyOnIt()
        {
            using (var testRoot = new TemporaryFolder("RepositoryTests"))
            {
                var progress = new NullProgress();
                HgRepository.CreateRepositoryInExistingDir(testRoot.Path, progress);
                // fileX and fileXRev are zero based indexing, since those local commit numbers in Hg are zero based indexing.
                using (var file0 = testRoot.GetNewTempFile(true))
                {
                    var repo = new HgRepository(testRoot.Path, new NullProgress());
                    repo.AddAndCheckinFile(file0.Path);
                    var file0Rev = repo.GetRevisionWorkingSetIsBasedOn();

                    // SUT
                    Assert.That(repo.UpdateToLongHash(file0Rev.Number.LongHash), Is.EqualTo(HgRepository.UpdateResults.AlreadyOnIt));
                }
            }
        }
Exemple #18
0
        public void GetFilesInRevision_OnlyOneRevisionInRepo_GivesAllFiles()
        {
            using (var testRoot = new TemporaryFolder("ChorusRetrieveTest"))
                using (var f = new TempFileFromFolder(testRoot))
                {
                    File.WriteAllText(f.Path, "one");

                    HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress);
                    var repo = new HgRepository(testRoot.Path, _progress);

                    repo.AddAndCheckinFile(f.Path);
                    repo.Commit(true, "initial");
                    var revisions = repo.GetAllRevisions();
                    Assert.AreEqual(1, revisions.Count);
                    var files = repo.GetFilesInRevision(revisions[0]);
                    Assert.AreEqual(1, files.Count());
                    Assert.AreEqual(f.Path, files.First().FullPath);
                }
        }
Exemple #19
0
        public void GetKnownRepositories_TwoInRepoSettings_GivesThem()
        {
            using (new MercurialIniForTests())
                using (var testRoot = new TemporaryFolder("ChorusHgSettingsTest"))
                {
                    HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress);
                    File.WriteAllText(testRoot.Combine(Path.Combine(".hg", "hgrc")), @"
[paths]
one = c:\intentionally bogus
two = http://foo.com");
                    var repo    = new HgRepository(testRoot.Path, _progress);
                    var sources = repo.GetRepositoryPathsInHgrc();
                    Assert.AreEqual(2, sources.Count());
                    Assert.AreEqual(@"c:\intentionally bogus", sources.First().URI);
                    Assert.AreEqual(@"http://foo.com", sources.Last().URI);
                    Assert.AreEqual(@"one", sources.First().Name);
                    Assert.AreEqual(@"two", sources.Last().Name);
                }
        }
Exemple #20
0
        public void Setup()
        {
            _progress = new ConsoleProgress();
            _testRoot = new TemporaryFolder("ChorusRetrieveTest");
            _tempFile = new TempFileFromFolder(_testRoot);
            File.WriteAllText(_tempFile.Path, "one");

            HgRepository.CreateRepositoryInExistingDir(_testRoot.Path, _progress);
            _repo = new HgRepository(_testRoot.Path, new NullProgress());
            _repo.AddAndCheckinFile(_tempFile.Path);
            _repo.Commit(true, "initial");


            File.WriteAllText(_tempFile.Path, "two");
            _repo.AddAndCheckinFile(_tempFile.Path);
            _repo.Commit(true, "changed to two");

            _changesets = _repo.GetAllRevisions();
            Assert.AreEqual(2, _changesets.Count);
        }
Exemple #21
0
 public void GetRevision_WithOneCommit_HasExpectedRevisionValues()
 {
     using (var testRoot = new TemporaryFolder("RepositoryTests"))
     {
         HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress);
         var repo = new HgRepository(testRoot.Path, new NullProgress());
         Assert.That(repo.Identifier, Is.Null);
         var rev = repo.GetAllRevisions().FirstOrDefault();
         Assert.That(rev, Is.Null);
         using (var f = testRoot.GetNewTempFile(true))
         {
             repo.AddAndCheckinFile(f.Path);
             rev = repo.GetRevisionWorkingSetIsBasedOn();
             Assert.That(rev.Number.LocalRevisionNumber, Is.EqualTo("0"));
             Assert.That(rev.Number.LongHash, Is.EqualTo(repo.Identifier));
             Assert.That(rev.Number.Hash.Length, Is.EqualTo(12));
             Assert.That(rev.Number.Hash, Is.EqualTo(repo.Identifier.Substring(0, 12)));
             Assert.That(rev.Number.Hash, Is.EqualTo(rev.Number.LongHash.Substring(0, 12)));
         }
     }
 }
Exemple #22
0
        public void EnsureTheseExtensionAreEnabled_AddingToExistingExtensions_NewAddedAndExistingNotDuplicated()
        {
            using (new MercurialIniForTests())
                using (var testRoot = new TemporaryFolder("ChorusHgSettingsTest"))
                {
                    HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress);
                    var repository = new HgRepository(testRoot.Path, new ConsoleProgress());
                    File.WriteAllText(testRoot.Combine(Path.Combine(".hg", "hgrc")), @"
[extensions]
a =
");
                    var extensions = new Dictionary <string, string>();
                    extensions.Add("a", "");
                    extensions.Add("b", "");
                    repository.EnsureTheseExtensionsAndFormatSet(extensions);

                    Assert.AreEqual(2, repository.GetEnabledExtension().Count(), "Extensions should contain just one 'a' and 'b'");
                    Assert.AreEqual("a", repository.GetEnabledExtension().ToArray()[0], "'a' extension was not retained.");
                    Assert.AreEqual("b", repository.GetEnabledExtension().ToArray()[1], "'b' extension should have been appended.");
                }
        }
Exemple #23
0
        public void EnsureTheseExtensionAreEnabled_ExtraExtensions_RemovesThem()
        {
            using (new MercurialIniForTests())
                using (var testRoot = new TemporaryFolder("ChorusHgSettingsTest"))
                {
                    HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress);
                    var repository = new HgRepository(testRoot.Path, new ConsoleProgress());
                    File.WriteAllText(testRoot.Combine(Path.Combine(".hg", "hgrc")), @"
[extensions]
a =
x =
");
                    var extensions = new Dictionary <string, string>();
                    extensions.Add("a", "");
                    extensions.Add("b", "");
                    repository.EnsureTheseExtensionsAndFormatSet(extensions);

                    Assert.AreEqual(2, repository.GetEnabledExtension().Count(), "Result should have 'a' and 'b' but no 'x'");
                    Assert.AreEqual("a", repository.GetEnabledExtension().ToArray()[0], "'a' was not kept.");
                    Assert.AreEqual("b", repository.GetEnabledExtension().ToArray()[1], "'b' did not replace 'x'");
                }
        }
Exemple #24
0
        public void EnsureTheseExtensionAreEnabled_someOthersEnabledAlready_StayEnabled()
        {
            using (new MercurialIniForTests())
                using (var testRoot = new TemporaryFolder("ChorusHgSettingsTest"))
                {
                    HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress);
                    var repository = new HgRepository(testRoot.Path, new ConsoleProgress());
                    File.WriteAllText(testRoot.Combine(Path.Combine(".hg", "hgrc")), @"
[extensions]
a =
x =
");
                    var extensions = new Dictionary <string, string>();
                    extensions.Add("a", "");
                    extensions.Add("b", "");
                    repository.EnsureTheseExtensionsAndFormatSet(extensions);

                    Assert.AreEqual(3, repository.GetEnabledExtension().Count());
                    Assert.AreEqual("a", repository.GetEnabledExtension().ToArray()[0]);
                    Assert.AreEqual("x", repository.GetEnabledExtension().ToArray()[1]);
                    Assert.AreEqual("b", repository.GetEnabledExtension().ToArray()[2]);
                }
        }
Exemple #25
0
 public void MakeListItem_MakesNormalItem()
 {
     using (var usb = new TemporaryFolder("clonetestUsb"))
     {
         var path = usb.Combine("test1");
         Directory.CreateDirectory(path);
         var testFile = Path.Combine(path, "test.file");
         File.WriteAllText(testFile, @"exist");
         var repo = HgRepository.CreateRepositoryInExistingDir(path, new NullProgress());
         repo.AddAndCheckinFile(testFile);
         var model = new CloneFromUsb();
         var item  = model.CreateListItemFor(path);
         Assert.That(item, Is.Not.Null, "model should have made a list item");
         Assert.That(item.Text, Is.EqualTo("test1"));
         Assert.That(item.Tag, Is.EqualTo(path));
         var    last            = File.GetLastWriteTime(path);
         string expectedSubitem = last.ToShortDateString() + " " + last.ToShortTimeString();                 // Not a great test, basically duplicates the impl
         Assert.That(item.SubItems[1].Text, Is.EqualTo(expectedSubitem));
         Assert.That(item.ToolTipText, Is.EqualTo(path));
         Assert.That(item.ImageIndex, Is.EqualTo(0));
         Assert.That(item.BackColor, Is.EqualTo(Color.FromKnownColor(KnownColor.Window)));
         Assert.That(item.ForeColor, Is.EqualTo(Color.FromKnownColor(KnownColor.WindowText)));
     }
 }
Exemple #26
0
        public void GetFilesInRevision_MultipleRevisionsInRepo_GivesCorrectFiles()
        {
            using (var testRoot = new TemporaryFolder("ChorusRetrieveTest"))
            {
                var temp = testRoot.Combine("filename with spaces");
                File.WriteAllText(temp, "one");
                using (var f = TempFile.TrackExisting(temp))
                {
                    HgRepository.CreateRepositoryInExistingDir(testRoot.Path, _progress);
                    var repo = new HgRepository(testRoot.Path, _progress);

                    repo.AddAndCheckinFile(f.Path);
                    repo.Commit(true, "initial");
                    File.WriteAllText(f.Path, "one two");
                    repo.Commit(true, "second");

                    var revisions = repo.GetAllRevisions();
                    Assert.AreEqual(2, revisions.Count);
                    var files = repo.GetFilesInRevision(revisions[0]);
                    Assert.AreEqual(1, files.Count());
                    Assert.AreEqual(f.Path, files.First().FullPath);
                }
            }
        }
        void Startup(object sender, StartupNewEventArgs e)
        {
            switch (e.SystemType)
            {
            default:
                throw new InvalidOperationException("Unrecognized type of shared system.");

            case SharedSystemType.New:
                // Create new repo with empty LIFT file.
                var newRepoPath     = LiftProjectServices.PathToProject(Liftproject);                     // DirectoryUtilities.GetUniqueFolderPath(LiftProjectServices.PathToProject(Liftproject));
                var newLiftPathname = Path.Combine(
                    newRepoPath,
                    Liftproject.LiftProjectName + ".lift");
                File.WriteAllText(newLiftPathname, Resources.kEmptyLiftFileXml);
                HgRepository.CreateRepositoryInExistingDir(newRepoPath, new NullProgress());
                var newRepo = new HgRepository(newRepoPath, new NullProgress());
                newRepo.AddAndCheckinFile(newLiftPathname);
                Liftproject.RepositoryIdentifier = newRepo.Identifier;
                break;

            case SharedSystemType.Extant:
                var result = _getSharedProject.GetSharedProjectUsing(MainForm, e.ExtantRepoSource, ProjectFilter, LiftProjectServices.BasePath, Liftproject.LiftProjectName);
                switch (result.CloneStatus)
                {
                //case CloneResult.OkToCreate: Not going to be returned.
                //  break;
                case CloneStatus.NotCreated:
                    // Clone not made for some reason.
                    MessageBox.Show(MainForm, Resources.kDidNotCloneSystem, Resources.kLiftSetUp, MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                    _liftBridgeView.Close();
                    return;

                case CloneStatus.Cancelled:
                    MessageBox.Show(MainForm, Resources.kUserCancelledCloneOperation, Resources.kSharingAttempCancelled, MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    _liftBridgeView.Close();
                    return;

                case CloneStatus.Created:
                    // Proceed
                    var clonedRepo = new HgRepository(result.ActualLocation, new NullProgress());
                    Liftproject.RepositoryIdentifier = clonedRepo.Identifier;
                    break;
                }

                if (BasicLexiconImport != null)
                {
                    var eventArgs = new LiftBridgeEventArgs(Liftproject.LiftPathname);
                    BasicLexiconImport(this, eventArgs);
                    if (eventArgs.Cancel)
                    {
                        // Event handler could not complete the basic import.
                        ImportFailureServices.RegisterBasicImportFailure((_liftBridgeView as Form), Liftproject);
                        _liftBridgeView.Close();
                        return;
                    }
                }
                break;
            }

            InstallExistingSystemControl();
        }
Exemple #28
0
        public void UpdateToLongHashOnNonEmptyRepoReturns_UpdateResults_Success()
        {
            using (var testRoot = new TemporaryFolder("RepositoryTests"))
            {
                var progress = new NullProgress();
                HgRepository.CreateRepositoryInExistingDir(testRoot.Path, progress);
                // fileX and fileXRev are zero based indexing, since those local commit numbers in Hg are zero based indexing.
                using (var file0 = testRoot.GetNewTempFile(true))
                {
                    var repo = new HgRepository(testRoot.Path, new NullProgress());

                    repo.AddAndCheckinFile(file0.Path);
                    var file0Rev = repo.GetRevisionWorkingSetIsBasedOn();
                    using (var file1 = testRoot.GetNewTempFile(true))
                    {
                        // On same branch.
                        repo.AddAndCheckinFile(file1.Path);
                        var file1Rev = repo.GetRevisionWorkingSetIsBasedOn();
                        using (var file2 = testRoot.GetNewTempFile(true))
                        {
                            // Make new branch.
                            repo.BranchingHelper.Branch(progress, "newbranch");
                            repo.AddAndCheckinFile(file2.Path);
                            var file2Rev = repo.GetRevisionWorkingSetIsBasedOn();

                            // Round 1: update from rev 0 to rev 2.
                            // Switch back to rev 0, using old method.
                            repo.Update("0");
                            var testRev = repo.GetRevisionWorkingSetIsBasedOn();
                            // It did move.
                            Assert.That(testRev.Number.LongHash, Is.EqualTo(file0Rev.Number.LongHash));
                            Assert.That(testRev.Branch, Is.EqualTo(string.Empty));                             // default branch returns string.Empty in mercurial.
                            // SUT
                            Assert.That(repo.UpdateToLongHash(file2Rev.Number.LongHash), Is.EqualTo(HgRepository.UpdateResults.Success));
                            testRev = repo.GetRevisionWorkingSetIsBasedOn();
                            Assert.That(testRev.Number.LongHash, Is.EqualTo(file2Rev.Number.LongHash));
                            Assert.That(testRev.Branch, Is.EqualTo("newbranch"));

                            // Round 2: update from rev 1 to rev 2.
                            // Set up for another pass to update to file2Rev from file3Rev
                            // Switch back to rev 1 (default branch), using old method.
                            repo.Update("1");
                            testRev = repo.GetRevisionWorkingSetIsBasedOn();
                            // It did move.
                            Assert.That(testRev.Number.LongHash, Is.EqualTo(file1Rev.Number.LongHash));
                            Assert.That(testRev.Branch, Is.EqualTo(string.Empty));                             // default branch returns string.Empty in mercurial.
                            // SUT
                            Assert.That(repo.UpdateToLongHash(file2Rev.Number.LongHash), Is.EqualTo(HgRepository.UpdateResults.Success));
                            testRev = repo.GetRevisionWorkingSetIsBasedOn();
                            Assert.That(testRev.Number.LongHash, Is.EqualTo(file2Rev.Number.LongHash));
                            Assert.That(testRev.Branch, Is.EqualTo("newbranch"));

                            // Round 3: downgrade from rev 2 to rev 0.
                            // Set up for another pass to update to file0Rev from file2Rev
                            // Switch back to rev 2 (newbranch branch), using old method.
                            repo.Update("2");
                            testRev = repo.GetRevisionWorkingSetIsBasedOn();
                            // It did move.
                            Assert.That(testRev.Number.LongHash, Is.EqualTo(file2Rev.Number.LongHash));
                            Assert.That(testRev.Branch, Is.EqualTo("newbranch"));
                            // SUT
                            Assert.That(repo.UpdateToLongHash(file0Rev.Number.LongHash), Is.EqualTo(HgRepository.UpdateResults.Success));
                            testRev = repo.GetRevisionWorkingSetIsBasedOn();
                            Assert.That(testRev.Number.LongHash, Is.EqualTo(file0Rev.Number.LongHash));
                            Assert.That(testRev.Branch, Is.EqualTo(string.Empty));                             // default branch returns string.Empty in mercurial.

                            // Round 4: downgrade from rev 2 to rev 1.
                            // Set up for another pass to update to file2Rev from file1Rev
                            // Switch back to rev 2 (newbranch branch), using old method.
                            repo.Update("2");
                            testRev = repo.GetRevisionWorkingSetIsBasedOn();
                            // It did move.
                            Assert.That(testRev.Number.LongHash, Is.EqualTo(file2Rev.Number.LongHash));
                            Assert.That(testRev.Branch, Is.EqualTo("newbranch"));
                            // SUT
                            Assert.That(repo.UpdateToLongHash(file1Rev.Number.LongHash), Is.EqualTo(HgRepository.UpdateResults.Success));
                            testRev = repo.GetRevisionWorkingSetIsBasedOn();
                            Assert.That(testRev.Number.LongHash, Is.EqualTo(file1Rev.Number.LongHash));
                            Assert.That(testRev.Branch, Is.EqualTo(string.Empty));                             // default branch returns string.Empty in mercurial.

                            // Round 5: downgrade from rev 1 to rev 0.
                            // Set up for another pass to update to file0Rev from file1Rev
                            // Switch back to rev 0 (default branch), using old method.
                            repo.Update("1");
                            testRev = repo.GetRevisionWorkingSetIsBasedOn();
                            // It did move.
                            Assert.That(testRev.Number.LongHash, Is.EqualTo(file1Rev.Number.LongHash));
                            Assert.That(testRev.Branch, Is.EqualTo(string.Empty));                             // default branch returns string.Empty in mercurial.
                            // SUT
                            Assert.That(repo.UpdateToLongHash(file0Rev.Number.LongHash), Is.EqualTo(HgRepository.UpdateResults.Success));
                            testRev = repo.GetRevisionWorkingSetIsBasedOn();
                            Assert.That(testRev.Number.LongHash, Is.EqualTo(file0Rev.Number.LongHash));
                            Assert.That(testRev.Branch, Is.EqualTo(string.Empty));                             // default branch returns string.Empty in mercurial.
                        }
                    }
                }
            }
        }
Exemple #29
0
        public static void MakeRepositoryForTest(string newRepositoryPath, string userId, IProgress progress)
        {
            var hg = HgRepository.CreateRepositoryInExistingDir(newRepositoryPath, progress);

            hg.SetUserNameInIni(userId, progress);
        }
Exemple #30
0
        public void UpdateToBranchHeadCallsReturnExpected_UpdateResults()
        {
            using (var testRoot = new TemporaryFolder("RepositoryTests"))
            {
                var progress = new NullProgress();
                HgRepository.CreateRepositoryInExistingDir(testRoot.Path, progress);
                // fileX and fileXRev are zero based indexing, since those local commit numbers in Hg are zero based indexing.
                using (var file0 = testRoot.GetNewTempFile(true))
                {
                    var repo = new HgRepository(testRoot.Path, new NullProgress());

                    // SUT
                    Assert.That(repo.UpdateToBranchHead("fakebranchname"), Is.EqualTo(HgRepository.UpdateResults.NoCommitsInRepository));

                    repo.AddAndCheckinFile(file0.Path);
                    var file0Rev = repo.GetRevisionWorkingSetIsBasedOn();

                    // SUT
                    Assert.That(repo.UpdateToBranchHead(file0Rev.Branch), Is.EqualTo(HgRepository.UpdateResults.AlreadyOnIt));

                    // SUT
                    Assert.That(repo.UpdateToBranchHead("NoSuchBranch"), Is.EqualTo(HgRepository.UpdateResults.NoSuchBranch));

                    using (var file1 = testRoot.GetNewTempFile(true))
                    {
                        // Make new branch.
                        repo.BranchingHelper.Branch(progress, "newbranch");
                        repo.AddAndCheckinFile(file1.Path);
                        var file1Rev = repo.GetRevisionWorkingSetIsBasedOn();
                        Assert.That(repo.UpdateToBranchHead(file1Rev.Branch), Is.EqualTo(HgRepository.UpdateResults.AlreadyOnIt));

                        // Go back to commit 0 and create another "newbranch", which should then be a two headed monster.
                        repo.Update("0");
                        repo.BranchingHelper.Branch(progress, "newbranch");
                        File.WriteAllText(file1.Path, @"new contents");
                        repo.Commit(true, "Force double headed branch");
                        var heads = repo.GetHeads().ToList();
                        Assert.That(heads.Count, Is.EqualTo(3));

                        // SUT
                        Assert.That(repo.UpdateToBranchHead(file1Rev.Branch), Is.EqualTo(HgRepository.UpdateResults.AlreadyOnIt));
                        var testRev = repo.GetRevisionWorkingSetIsBasedOn();
                        Assert.That(testRev.Branch, Is.EqualTo("newbranch"));
                        Assert.That(testRev.Number.LocalRevisionNumber, Is.EqualTo("2"));

                        // Switch to older head of 'newbranch'
                        // (Goes from rev 2 back to rev 1, both of which are on the same branch (newbranch).)
                        repo.Update("1");

                        // SUT
                        // Returns "Success", because we moved from rev 1 to rev 2 (higher rev number) in the same branch, which branch has two heads.)
                        Assert.That(repo.UpdateToBranchHead(file1Rev.Branch), Is.EqualTo(HgRepository.UpdateResults.Success));
                        testRev = repo.GetRevisionWorkingSetIsBasedOn();
                        Assert.That(testRev.Branch, Is.EqualTo("newbranch"));
                        Assert.That(testRev.Number.LocalRevisionNumber, Is.EqualTo("2"));

                        // Switch to commit 0.
                        repo.Update("0");
                        testRev = repo.GetRevisionWorkingSetIsBasedOn();
                        Assert.That(testRev.Branch, Is.EqualTo(string.Empty));
                        Assert.That(testRev.Number.LocalRevisionNumber, Is.EqualTo("0"));

                        // SUT
                        Assert.That(repo.UpdateToBranchHead(file1Rev.Branch), Is.EqualTo(HgRepository.UpdateResults.Success));
                        testRev = repo.GetRevisionWorkingSetIsBasedOn();
                        Assert.That(testRev.Branch, Is.EqualTo("newbranch"));
                        Assert.That(testRev.Number.LocalRevisionNumber, Is.EqualTo("2"));
                    }
                }
            }
        }