Ejemplo n.º 1
0
 ///<summary>
 /// Makes a Mercurial clone of a repository from sourcePath to parentDirectoryToPutCloneIn
 ///</summary>
 ///<param name="sourcePath">Existing Hg repo</param>
 ///<param name="parentDirectoryToPutCloneIn">Target folder for new clone</param>
 ///<param name="progress">Progress indicator object</param>
 ///<returns>Directory that clone was actually placed in (allows for renaming to avoid duplicates)</returns>
 public string MakeClone(string sourcePath, string parentDirectoryToPutCloneIn, IProgress progress)
 {
     return(HgHighLevel.MakeCloneFromLocalToLocal(sourcePath,
                                                  Path.Combine(parentDirectoryToPutCloneIn, Path.GetFileName(sourcePath)),
                                                  true,
                                                  progress));
 }
Ejemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="targetPath">does not inclue the project folder dir</param>
 public string SetupClone(string targetPath)
 {
     //return GetSynchronizer().MakeClone(Path.Combine(targetPath, BobSetup.ProjectFolderName), true);
     return(HgHighLevel.MakeCloneFromLocalToLocal(_languageProjectPath,
                                                  Path.Combine(targetPath, BobSetup.ProjectFolderName), true,
                                                  _progress));
 }
Ejemplo n.º 3
0
        public void SyncNow_AlreadySetupFauxUsbAvailable_UsbGetsSync()
        {
            SyncOptions  options      = new SyncOptions();
            Synchronizer synchronizer = Synchronizer.FromProjectConfiguration(_project, _progress);

            synchronizer.SyncNow(options);

            options.RepositorySourcesToTry.Add(synchronizer.UsbPath);
            string usbDirectory = Path.Combine(UsbKeyRepositorySource.RootDirForUsbSourceDuringUnitTest, "foo project");

            // synchronizer.MakeClone(usbDirectory, true);
            HgHighLevel.MakeCloneFromLocalToLocal(synchronizer.Repository.PathToRepo, usbDirectory, true, _progress);

            string contents = File.ReadAllText(Path.Combine(usbDirectory, "foo.txt"));

            Assert.AreEqual("version one", contents);
            WriteTestFile("version two");
            //_progress.ShowVerbose = true;
            options.CheckinDescription = "Changing to two";
            synchronizer.SyncNow(options);
            var usb = new HgRepository(usbDirectory, _progress);

            Assert.AreEqual("Changing to two", usb.GetTip().Summary);

            //did it update too (which we should do with usb, unless we switch to leave them as "bare" .hgs)?
            contents = File.ReadAllText(Path.Combine(usbDirectory, "foo.txt"));
            Assert.AreEqual("version two", contents);
        }
Ejemplo n.º 4
0
        public void SyncNow_AlreadySetupFauxUsbAvailable_UsbGetsSync()
        {
            // setup main repo
            SyncOptions  options      = new SyncOptions();
            Synchronizer synchronizer = Synchronizer.FromProjectConfiguration(_project, _progress);

            synchronizer.SyncNow(options);

            // setup faux USB repo
            options.RepositorySourcesToTry.Add(synchronizer.UsbPath);
            string usbDirectory = Path.Combine(UsbKeyRepositorySource.RootDirForUsbSourceDuringUnitTest, "foo project");

            HgHighLevel.MakeCloneFromLocalToUsb(synchronizer.Repository.PathToRepo, usbDirectory, _progress);

            // make a change to the main repo and sync
            WriteTestFile("version two");
            options.CheckinDescription = "Changing to two";
            synchronizer.SyncNow(options);

            // check if USB repo received the change
            var usb = new HgRepository(usbDirectory, _progress);

            Assert.AreEqual("Changing to two", usb.GetTip().Summary);
            // ensure that the USB repo is still bare
            Assert.That(File.Exists(Path.Combine(usbDirectory, "foo.txt")), Is.False);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// used for local sources (usb, sd media, etc)
        /// </summary>
        private void TryToMakeCloneForSource(RepositoryAddress repoDescriptor)
        {
            var possibleRepoCloneUris = repoDescriptor.GetPossibleCloneUris(Repository.Identifier, RepoProjectName, _progress);

            if (possibleRepoCloneUris == null)
            {
                _progress.WriteMessage("No Uris available for cloning to {0}",
                                       repoDescriptor.Name);
                return;
            }

            foreach (var uri in possibleRepoCloneUris)
            {
                // target may be uri, or some other folder.
                var target = HgRepository.GetUniqueFolderPath(
                    _progress,
                    //"Folder at {0} already exists, so it can't be used. Creating clone in {1}, instead.",
                    RepositoryAddress.DuplicateWarningMessage.Replace(RepositoryAddress.MediumVariable, "USB flash drive"),
                    uri);
                try
                {
                    _progress.WriteMessage("Copying repository to {0}...", repoDescriptor.GetFullName(target));
                    _progress.WriteVerbose("({0})", target);
                    HgHighLevel.MakeCloneFromLocalToUsb(_localRepositoryPath, target, _progress);
                    return;
                }
                catch (Exception error)
                {
                    _progress.WriteError("Could not create repository on {0}. Error follow:", target);
                    _progress.WriteException(error);
                    // keep looping
                }
            }
        }
Ejemplo n.º 6
0
        public void SyncNow_BackupAlreadySetUp_GetsSync()
        {
            SyncOptions options = new SyncOptions();

            _synchronizer.SyncNow(options);
            string projectDirOnBackup = Path.Combine(_pathToBackupFolder, "foo project.2");

            //_synchronizer.MakeClone(projectDirOnBackup, true);
            HgHighLevel.MakeCloneFromLocalToLocal(_synchronizer.Repository.PathToRepo, projectDirOnBackup, true, _progress);

            string contents = File.ReadAllText(Path.Combine(projectDirOnBackup, "foo.txt"));

            Assert.AreEqual("version one", contents);
            WriteTestFile("version two");
        }
Ejemplo n.º 7
0
        private RepositoryWithFilesSetup(string userName, RepositoryWithFilesSetup cloneFromUser)
        {
            Progress   = new MultiProgress(new IProgress[] { new ConsoleProgress(), _stringProgress });
            RootFolder = new TemporaryFolder("ChorusTest-" + userName + "-" + Guid.NewGuid());
            Console.WriteLine("TestRepository Cloned: {0}", RootFolder.Path);
            string pathToProject = RootFolder.Combine(Path.GetFileName(cloneFromUser.ProjectFolder.Path));

            //cloneFromUser.Synchronizer.MakeClone(pathToProject, true);
            HgHighLevel.MakeCloneFromUsbToLocal(cloneFromUser.Repository.PathToRepo, pathToProject, Progress);

            ProjectFolder = TemporaryFolder.TrackExisting(RootFolder.Combine("foo project"));
            string pathToOurLiftFile = ProjectFolder.Combine(Path.GetFileName(cloneFromUser.UserFile.Path));

            UserFile = TempFile.TrackExisting(pathToOurLiftFile);

            Init(userName);
        }
Ejemplo n.º 8
0
 public void CloneToUsbWithoutUpdateFollowedByIdentifierDoesNotAffectHgrc()
 {
     using (var repo = new RepositorySetup("source"))
         using (var f = new TemporaryFolder("clonetest"))
         {
             // The MakeCloneFromLocalToLocal with false on alsoDoCheckout is the core of the usb clone operation.
             // We need to make sure that this clone is bare of extensions, and remains so after the identifier is checked.
             HgHighLevel.MakeCloneFromLocalToUsb(repo.ProjectFolder.Path, f.Path, new NullProgress());
             var cloneRepo    = new HgRepository(f.Path, new NullProgress());
             var hgFolderPath = Path.Combine(f.Path, ".hg");
             Assert.IsTrue(Directory.Exists(hgFolderPath));
             var hgrcLines = File.ReadAllLines(Path.Combine(hgFolderPath, "hgrc"));
             //SUT
             CollectionAssert.DoesNotContain(hgrcLines, "[extensions]", "extensions section created in bare clone");
             var id = cloneRepo.Identifier;
             CollectionAssert.DoesNotContain(hgrcLines, "[extensions]", "extensions section created after Identifier property read");
         }
 }
Ejemplo n.º 9
0
        public void CanShareConflictingChangeViaUsb()
        {
            ConsoleProgress progress = new ConsoleProgress();
            BobSetup        bobSetup = new BobSetup(progress, _pathToTestRoot);

            bobSetup.ChangeTextFile();
            string usbSourcePath = Path.Combine(_pathToTestRoot, "USB-A");

            Directory.CreateDirectory(usbSourcePath);
            string       usbProjectPath = bobSetup.SetupClone(usbSourcePath);
            Synchronizer usbRepo        = Synchronizer.FromProjectConfiguration(BobSetup.CreateFolderConfig(usbProjectPath), progress);

            Synchronizer bobSynchronizer = bobSetup.GetSynchronizer();

            //Sally gets the usb and uses it to clone herself a repository
            string sallySourcePath = Path.Combine(_pathToTestRoot, "sally");

            Directory.CreateDirectory(sallySourcePath);
            //string sallyRepoPath = usbRepo.MakeClone(Path.Combine(sallySourcePath, BobSetup.ProjectFolderName), true);
            string sallyRepoPath = HgHighLevel.MakeCloneFromUsbToLocal(usbRepo.Repository.PathToRepo, Path.Combine(sallySourcePath, BobSetup.ProjectFolderName), progress);


            //Now bob sets up the conflict

            File.WriteAllText(bobSetup.PathToText, "Bob's new idea");
            SyncOptions bobOptions = new SyncOptions();

            bobOptions.CheckinDescription = "changed my mind";
            bobOptions.DoMergeWithOthers  = false;           // pretend the usb key isn't there
            bobOptions.DoPullFromOthers   = false;           // pretend the usb key isn't there
            bobOptions.DoSendToOthers     = false;
            RepositoryAddress usbPath = RepositoryAddress.Create("usba source", Path.Combine(usbSourcePath, RepositoryAddress.ProjectNameVariable), false);

            bobOptions.RepositorySourcesToTry.Add(usbPath);
            bobSynchronizer.SyncNow(bobOptions);

            ProjectFolderConfiguration sallyProject = BobSetup.CreateFolderConfig(sallyRepoPath);

            Synchronizer sallySynchronizer = Synchronizer.FromProjectConfiguration(sallyProject, progress);

            sallySynchronizer.Repository.SetUserNameInIni("sally", new NullProgress());

            //now she modifies a file
            File.WriteAllText(Path.Combine(sallyRepoPath, Path.Combine("lexicon", "foo.abc")), "Sally was here");

            //and syncs, which pushes back to the usb key
            SyncOptions sallyOptions = new SyncOptions();

            sallyOptions.CheckinDescription = "making sally's mark on foo.abc";
            sallyOptions.RepositorySourcesToTry.Add(usbPath);
            sallyOptions.DoPullFromOthers  = true;
            sallyOptions.DoMergeWithOthers = true;
            sallyOptions.DoSendToOthers    = true;
            sallySynchronizer.SyncNow(sallyOptions);

            //bob still doesn't have direct access to sally's repo... it's in some other city
            // but now the usb comes back to him
            // SyncOptions bobOptions = new SyncOptions();
            bobOptions.CheckinDescription = "Getting from sally, i hope";
            bobOptions.DoPullFromOthers   = true;
            bobOptions.DoSendToOthers     = true;
            bobOptions.DoMergeWithOthers  = true;
            bobSynchronizer.SyncNow(bobOptions);

            // With sync set as 'WeWin'
            Assert.AreEqual("Bob's new idea", File.ReadAllText(bobSetup.PathToText));
            var notesPath = Path.Combine(Path.Combine(Path.Combine(usbSourcePath, BobSetup.ProjectFolderName), "lexicon"), "foo.abc.ChorusNotes");

            AssertThatXmlIn.File(notesPath).HasSpecifiedNumberOfMatchesForXpath("//notes/annotation[@class='mergeConflict']", 1);

            //The conflict has now been created, in the merge with Bob, make a new conflict and make sure that when Sally does the next sync both conflicts are
            //present in the ChorusNotes.
            File.WriteAllText(Path.Combine(sallyRepoPath, Path.Combine("lexicon", "foo.abc")), "Sally changed her mind");
            File.WriteAllText(bobSetup.PathToText, "Bob changed his mind.");
            bobOptions.CheckinDescription = "Bob makes conflicting change.";
            bobSynchronizer.SyncNow(bobOptions);
            sallyOptions.CheckinDescription = "Sally makes conflicting change.";
            sallySynchronizer.SyncNow(sallyOptions);
            AssertThatXmlIn.File(notesPath).HasSpecifiedNumberOfMatchesForXpath("//notes/annotation[@class='mergeConflict']", 2);
        }
Ejemplo n.º 10
0
 private void MakeClone(string pathToNewRepo)
 {
     HgHighLevel.MakeCloneFromUsbToLocal(ProjectFolder.Path, pathToNewRepo, Progress);
 }