Пример #1
0
        public void CanGetNewFileFromAnotherRep()
        {
            ConsoleProgress progress = new ConsoleProgress();
            BobSetup        bobSetup = new BobSetup(progress, _pathToTestRoot);

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

            Directory.CreateDirectory(usbPath);
            bobSetup.SetupClone(usbPath);

            RepositoryAddress otherDirPath = RepositoryAddress.Create("USBA", Path.Combine(usbPath, RepositoryAddress.ProjectNameVariable), false);
            Synchronizer      bob          = bobSetup.GetSynchronizer();

            bob.ExtraRepositorySources.Add(otherDirPath);

            //now stick a new file over in the "usb", so we can see if it comes back to us
            File.WriteAllText(Path.Combine(otherDirPath.GetPotentialRepoUri(bob.Repository.Identifier, BobSetup.ProjectFolderName, progress), "incoming.abc"), "this would be a file coming in");
            var options = GetFullSyncOptions("adding a file to the usb for some reason");
            ProjectFolderConfiguration usbProject = BobSetup.CreateFolderConfig(Path.Combine(usbPath, BobSetup.ProjectFolderName));
            var synchronizer = Synchronizer.FromProjectConfiguration(usbProject, progress);

            synchronizer.Repository.SetUserNameInIni("usba", progress);
            synchronizer.SyncNow(options);

            //now we should get that file
            options = GetFullSyncOptions("test getting new file from usb");
            options.DoMergeWithOthers = false;
            options.DoSendToOthers    = false;
            options.RepositorySourcesToTry.Add(otherDirPath);
            bob.SyncNow(options);
            Assert.That(Path.Combine(bobSetup._languageProjectPath, "incoming.abc"), Does.Exist);
        }
Пример #2
0
        public void CanCollaborateOnLift()
        {
            ConsoleProgress progress = new ConsoleProgress();
            BobSetup        bobSetup = new BobSetup(progress, _pathToTestRoot);

            bobSetup.ChangeTextFile();

            //Ok, this is unrealistic, but we just clone Bob onto Sally
            string sallyMachineRoot = Path.Combine(_pathToTestRoot, "sally");

            Directory.CreateDirectory(sallyMachineRoot);
            string sallyProjectRoot = bobSetup.SetupClone(sallyMachineRoot);
            ProjectFolderConfiguration sallyProject = BobSetup.CreateFolderConfig(sallyProjectRoot);

            var repository = HgRepository.CreateOrUseExisting(sallyProject.FolderPath, progress);

            repository.SetUserNameInIni("sally", progress);

            // bob makes a change and syncs
            File.WriteAllText(bobSetup._pathToLift, LiftFileStrings.lift12Dog);
            var bobOptions = new SyncOptions
            {
                CheckinDescription = "added 'dog'",
                DoMergeWithOthers  = false,                                                                     // just want a fast checkin
                DoSendToOthers     = false,                                                                     // just want a fast checkin
                DoPullFromOthers   = false                                                                      // just want a fast checkin
            };

            bobSetup.GetSynchronizer().SyncNow(bobOptions);

            //now Sally modifies the original file, not having seen Bob's changes yet
            var sallyPathToLift = Path.Combine(sallyProject.FolderPath, Path.Combine("lexicon", "foo.lift"));

            File.WriteAllText(sallyPathToLift, LiftFileStrings.lift12Cat);

            //Sally syncs, pulling in Bob's change, and encountering a need to merge (no conflicts)
            var sallyOptions = new SyncOptions
            {
                CheckinDescription = "adding cat",
                DoPullFromOthers   = true,
                DoSendToOthers     = true,
                DoMergeWithOthers  = true
            };

            sallyOptions.RepositorySourcesToTry.Add(RepositoryAddress.Create("bob's machine", bobSetup.BobProjectPath, false));

            var synchronizer = Synchronizer.FromProjectConfiguration(sallyProject, progress);

            synchronizer.SyncNow(sallyOptions);

            //Debug.WriteLine("bob's: " + File.ReadAllText(bobSetup._pathToLift));
            var contents = File.ReadAllText(sallyPathToLift);

            //Debug.WriteLine("sally's: " + contents);
            Assert.That(contents, Does.Contain("cat"));
            Assert.That(contents, Does.Contain("dog"));
        }
Пример #3
0
        public void TipUpdatedPostMerge()
        {
            ConsoleProgress progress        = new ConsoleProgress();
            BobSetup        bobSetup        = new BobSetup(progress, _pathToTestRoot);
            var             bobSynchronizer = bobSetup.GetSynchronizer();

            //set up two branches to trigger issue
            SetAdjunctModelVersion(bobSynchronizer, "notdefault");             // Bob is on 'default' branch
            bobSetup.ChangeTextFile(bobSynchronizer);

            //Ok, this is unrealistic, but we just clone Bob onto Sally
            var hubRoot          = Path.Combine(_pathToTestRoot, "Hub");
            var sallyMachineRoot = Path.Combine(_pathToTestRoot, "sally");

            Directory.CreateDirectory(sallyMachineRoot);
            Directory.CreateDirectory(hubRoot);
            var sallyProjectRoot = bobSetup.SetupClone(sallyMachineRoot);
            var hubProjectRoot   = bobSetup.SetupClone(hubRoot);
            var sallyProject     = BobSetup.CreateFolderConfig(sallyProjectRoot);
            var hubProject       = BobSetup.CreateFolderConfig(hubProjectRoot);

            var repository = HgRepository.CreateOrUseExisting(sallyProject.FolderPath, progress);

            repository.SetUserNameInIni("sally", progress);

            // bob makes a change and syncs
            File.WriteAllText(bobSetup._pathToLift, LiftFileStrings.lift12Dog);
            var bobOptions = new SyncOptions
            {
                CheckinDescription = "added 'dog'",
                DoMergeWithOthers  = true,
                DoSendToOthers     = true,
                DoPullFromOthers   = true
            };

            bobOptions.RepositorySourcesToTry.Add(RepositoryAddress.Create("Hub", hubProject.FolderPath, false));

            //now Sally modifies the original file, not having seen Bob's changes yet
            var sallyPathToLift = Path.Combine(sallyProject.FolderPath, Path.Combine("lexicon", "foo.lift"));

            File.WriteAllText(sallyPathToLift, LiftFileStrings.lift12Cat);

            //Sally syncs, pulling in Bob's change, and encountering a need to merge (no conflicts)
            var sallyOptions = new SyncOptions
            {
                CheckinDescription = "adding cat",
                DoPullFromOthers   = true,
                DoSendToOthers     = true,
                DoMergeWithOthers  = true
            };

            sallyOptions.RepositorySourcesToTry.Add(RepositoryAddress.Create("Hub", hubProject.FolderPath, false));

            var sallySyncer = Synchronizer.FromProjectConfiguration(sallyProject, progress);

            SetAdjunctModelVersion(sallySyncer, "notdefault");
            sallySyncer.SyncNow(sallyOptions);
            bobSynchronizer.SyncNow(bobOptions);
            // bob makes a change and syncs
            File.WriteAllText(bobSetup._pathToLift, LiftFileStrings.lift12DogAnt);
            bobSynchronizer.SyncNow(bobOptions);
            sallyOptions.DoSendToOthers = false;
            sallySyncer.SyncNow(sallyOptions);
            //Debug.WriteLine("bob's: " + File.ReadAllText(bobSetup._pathToLift));
            var contents = File.ReadAllText(sallyPathToLift);

            //Debug.WriteLine("sally's: " + contents);
            Assert.That(contents, Does.Contain("ant"));
            Assert.That(contents, Does.Contain("dog"));
        }
Пример #4
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);
        }