예제 #1
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.
             }
         }
     }
 }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
0
        public void AddingRepositoryWithinAnotherRepositoryWithEmptyStringDirectoryThrows()
        {
            using (var tempParent = new TemporaryFolder("ChorusParent"))
            {
                var parentRepo = new HgRepository(tempParent.Path, new NullProgress());
                parentRepo.Init();
                var parentFile = tempParent.GetNewTempFile(true);
                File.WriteAllText(parentFile.Path, "New Content");
                parentRepo.AddAndCheckinFile(parentFile.Path);

                Assert.Throws<ArgumentNullException>(() => HgRepository.CreateOrUseExisting("", new NullProgress()));
            }
        }
예제 #5
0
        public void AddingRepositoryWithinAnotherRepositoryWithNullDirectoryThrows()
        {
            using (var tempParent = new TemporaryFolder("ChorusParent"))
            {
                var parentRepo = new HgRepository(tempParent.Path, new NullProgress());
                parentRepo.Init();
                var parentFile = tempParent.GetNewTempFile(true);
                File.WriteAllText(parentFile.Path, "New Content");
                parentRepo.AddAndCheckinFile(parentFile.Path);

                Assert.Throws <ArgumentNullException>(() => HgRepository.CreateOrUseExisting(null, new NullProgress()));
            }
        }
예제 #6
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);
         }
     }
 }
예제 #7
0
        public void AddingRepositoryWithinAnotherRepositoryWithNonexistantDirectoryThrows()
        {
            using (var tempParent = new TemporaryFolder("ChorusParent"))
            {
                var parentRepo = new HgRepository(tempParent.Path, new NullProgress());
                parentRepo.Init();
                var parentFile = tempParent.GetNewTempFile(true);
                File.WriteAllText(parentFile.Path, "New Content");
                parentRepo.AddAndCheckinFile(parentFile.Path);

                var parentFolder = tempParent.Path;
                var nonexistantDirectory = Path.Combine(parentFolder, "Child");
                Assert.Throws<InvalidOperationException>(() => HgRepository.CreateOrUseExisting(nonexistantDirectory, new NullProgress()));
            }
        }
예제 #8
0
        public void AddingRepositoryWithinAnotherRepositoryWithNonexistantFileThrows()
        {
            using (var tempParent = new TemporaryFolder("ChorusParent"))
            {
                var parentRepo = new HgRepository(tempParent.Path, new NullProgress());
                parentRepo.Init();
                var parentFile = tempParent.GetNewTempFile(true);
                File.WriteAllText(parentFile.Path, "New Content");
                parentRepo.AddAndCheckinFile(parentFile.Path);

                var parentFolder    = tempParent.Path;
                var nonexistantFile = Path.Combine(parentFolder, "bogusfile.txt");
                Assert.Throws <InvalidOperationException>(() => HgRepository.CreateOrUseExisting(nonexistantFile, new NullProgress()));
            }
        }
예제 #9
0
        public void AddingRepositoryWithinAnotherRepositoryFromDirectoryNameIsDifferentRepository()
        {
            using (var tempParent = new TemporaryFolder("ChorusParent"))
            {
                var parentRepo = new HgRepository(tempParent.Path, new NullProgress());
                parentRepo.Init();
                var parentFile = tempParent.GetNewTempFile(true);
                File.WriteAllText(parentFile.Path, "New Content");
                parentRepo.AddAndCheckinFile(parentFile.Path);

                var parentFolder = tempParent.Path;
                var dirInfo = Directory.CreateDirectory(Path.Combine(parentFolder, "Child"));
                var childRepo = HgRepository.CreateOrUseExisting(dirInfo.FullName, new NullProgress());
                Assert.AreNotEqual(parentFolder, childRepo.PathToRepo);
            }
        }
예제 #10
0
        public void AddingRepositoryWithinAnotherRepositoryFromDirectoryNameIsDifferentRepository()
        {
            using (var tempParent = new TemporaryFolder("ChorusParent"))
            {
                var parentRepo = new HgRepository(tempParent.Path, new NullProgress());
                parentRepo.Init();
                var parentFile = tempParent.GetNewTempFile(true);
                File.WriteAllText(parentFile.Path, "New Content");
                parentRepo.AddAndCheckinFile(parentFile.Path);

                var parentFolder = tempParent.Path;
                var dirInfo      = Directory.CreateDirectory(Path.Combine(parentFolder, "Child"));
                var childRepo    = HgRepository.CreateOrUseExisting(dirInfo.FullName, new NullProgress());
                Assert.AreNotEqual(parentFolder, childRepo.PathToRepo);
            }
        }
예제 #11
0
        public void HasExtantRepositories()
        {
            using (var parentFolder = new TemporaryFolder("parentFolder"))
                using (var childFolder = new TemporaryFolder(parentFolder, "childFolder"))
                {
                    var newFile = Path.Combine(childFolder.Path, "test.txt");
                    File.WriteAllText(newFile, "some stuff");
                    var repo = new HgRepository(childFolder.Path, new NullProgress());
                    repo.Init();
                    repo.AddAndCheckinFile(newFile);

                    var extantRepoIdentifiers = GetSharedProjectModel.ExtantRepoIdentifiers(parentFolder.Path, null);
                    Assert.AreEqual(1, extantRepoIdentifiers.Count);
                    Assert.IsTrue(extantRepoIdentifiers.ContainsKey(repo.Identifier));
                    Assert.That(extantRepoIdentifiers[repo.Identifier], Is.EqualTo("childFolder"));
                }
        }
예제 #12
0
        public void HasExtantRepositories()
        {
            using (var parentFolder = new TemporaryFolder("parentFolder"))
            using (var childFolder = new TemporaryFolder(parentFolder, "childFolder"))
            {
                var newFile = Path.Combine(childFolder.Path, "test.txt");
                File.WriteAllText(newFile, "some stuff");
                var repo = new HgRepository(childFolder.Path, new NullProgress());
                repo.Init();
                repo.AddAndCheckinFile(newFile);

                var extantRepoIdentifiers = GetSharedProjectModel.ExtantRepoIdentifiers(parentFolder.Path, null);
                Assert.AreEqual(1, extantRepoIdentifiers.Count);
                Assert.IsTrue(extantRepoIdentifiers.ContainsKey(repo.Identifier));
                Assert.That(extantRepoIdentifiers[repo.Identifier], Is.EqualTo("childFolder"));
            }
        }
예제 #13
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));
                }
            }
        }
예제 #14
0
 public void RepositoryRecoversFromIncompleteMerge()
 {
     using (var tempRepo = new TemporaryFolder("ChorusIncompleteMerge"))
     {
         var baseDir = PathHelper.NormalizePath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase));
         baseDir = PathHelper.StripFilePrefix(baseDir);
         string  zipPath = Path.Combine(baseDir, Path.Combine("VcsDrivers", Path.Combine("TestData", "incompletemergerepo.zip")));
         FastZip zipFile = new FastZip();
         zipFile.ExtractZip(zipPath, tempRepo.Path, null);
         var hgRepo = new HgRepository(tempRepo.Path, new NullProgress());
         hgRepo.CheckAndUpdateHgrc();
         var parentFile = tempRepo.GetNewTempFile(true);
         File.WriteAllText(parentFile.Path, "New Content");
         var exception = Assert.Throws <ApplicationException>(() => hgRepo.AddAndCheckinFile(parentFile.Path));
         Assert.That(exception.Message.Contains("Unable to recover") && !exception.Message.Contains("unresolved merge"),
                     String.Format("Repository should have conflict in retrying the merge, but not have an incomplete merge: {0}", exception.Message));
     }
 }
예제 #15
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));
                }
            }
        }
예제 #16
0
        public void ExtantRepositories_FindsRepoInOtherRepoLocation()
        {
            using (var parentFolder = new TemporaryFolder("parentFolder"))
                using (var childFolder = new TemporaryFolder(parentFolder, "childFolder"))
                    using (var otherFolder = new TemporaryFolder(childFolder, "otherRepositories"))
                        using (var repoFolder = new TemporaryFolder(otherFolder, "LIFT"))
                        {
                            var newFile = Path.Combine(repoFolder.Path, "test.txt");
                            File.WriteAllText(newFile, "some stuff");
                            var repo = new HgRepository(childFolder.Path, new NullProgress());
                            repo.Init();
                            repo.AddAndCheckinFile(newFile);

                            var extantRepoIdentifiers = GetSharedProjectModel.ExtantRepoIdentifiers(parentFolder.Path, "otherRepositories");
                            Assert.AreEqual(1, extantRepoIdentifiers.Count);
                            Assert.That(extantRepoIdentifiers, Does.ContainKey(repo.Identifier));
                            Assert.That(extantRepoIdentifiers[repo.Identifier], Is.EqualTo("childFolder"));
                        }
        }
예제 #17
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);
                }
        }
예제 #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);
                }
        }
예제 #19
0
        public void RepositoryRecoversFromIncompleteMerge()
        {
            using (var tempRepo = new TemporaryFolder("ChorusIncompleteMerge"))
            {
                var baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
#if MONO
                baseDir = baseDir.Replace(@"file:", null);
#else
                baseDir = baseDir.Replace(@"file:\", null);
#endif
                var zipFile = new ZipFile(Path.Combine(baseDir, Path.Combine("VcsDrivers", Path.Combine("TestData", "incompletemergerepo.zip"))));
                zipFile.ExtractAll(tempRepo.Path);
                var hgRepo = new HgRepository(tempRepo.Path, new NullProgress());
                hgRepo.CheckAndUpdateHgrc();
                var parentFile = tempRepo.GetNewTempFile(true);
                File.WriteAllText(parentFile.Path, "New Content");
                var exception = Assert.Throws <ApplicationException>(() => hgRepo.AddAndCheckinFile(parentFile.Path));
                Assert.That(exception.Message.Contains("Unable to recover") && !exception.Message.Contains("unresolved merge"), "Repository should have conflict in retrying the merge, but not have an incomplete merge");
            }
        }
예제 #20
0
        public void NotesFileInOtherHgRepoNotInThisAnnotationrepository()
        {
            using (var fred = new RepositorySetup("fred"))
            {
                var fredNotesPathname = Path.Combine(fred.ProjectFolder.Path, "fred.ChorusNotes");
                File.WriteAllText(fredNotesPathname, "<notes version='0'><annotation><message/></annotation></notes>");
                fred.Repository.AddAndCheckinFile(fredNotesPathname);

                var sallyRepoPath = Path.Combine(fred.ProjectFolder.Path, "SallyRepo");
                Directory.CreateDirectory(sallyRepoPath);
                var sallyRepo = new HgRepository(sallyRepoPath, new NullProgress());
                sallyRepo.Init();
                var sallyNotesPathname = Path.Combine(sallyRepoPath, "sally.ChorusNotes");
                File.WriteAllText(sallyNotesPathname, "<notes version='0'><annotation><message/></annotation></notes>");
                sallyRepo.AddAndCheckinFile(sallyNotesPathname);

                var annRepositories = AnnotationRepository.CreateRepositoriesFromFolder(fred.ProjectFolder.Path, new NullProgress()).ToList();
                Assert.AreEqual(1, annRepositories.Count);
                Assert.AreEqual("fred.ChorusNotes", Path.GetFileName(annRepositories[0].AnnotationFilePath));
            }
        }
예제 #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)));
         }
     }
 }
예제 #22
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);
                }
            }
        }
예제 #23
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);
                }
            }
        }
예제 #24
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);
         }
     }
 }
예제 #25
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"));
                    }
                }
            }
        }
        public void NotesFileInOtherHgRepoNotInThisAnnotationrepository()
        {
            using (var fred = new RepositorySetup("fred"))
            {
                var fredNotesPathname = Path.Combine(fred.ProjectFolder.Path, "fred.ChorusNotes");
                File.WriteAllText(fredNotesPathname, "<notes version='0'><annotation><message/></annotation></notes>");
                fred.Repository.AddAndCheckinFile(fredNotesPathname);

                var sallyRepoPath = Path.Combine(fred.ProjectFolder.Path, "SallyRepo");
                Directory.CreateDirectory(sallyRepoPath);
                var sallyRepo = new HgRepository(sallyRepoPath, new NullProgress());
                sallyRepo.Init();
                var sallyNotesPathname = Path.Combine(sallyRepoPath, "sally.ChorusNotes");
                File.WriteAllText(sallyNotesPathname, "<notes version='0'><annotation><message/></annotation></notes>");
                sallyRepo.AddAndCheckinFile(sallyNotesPathname);

                var annRepositories = AnnotationRepository.CreateRepositoriesFromFolder(fred.ProjectFolder.Path, new NullProgress()).ToList();
                Assert.AreEqual(1, annRepositories.Count);
                Assert.AreEqual("fred.ChorusNotes", Path.GetFileName(annRepositories[0].AnnotationFilePath));
            }
        }
        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();
        }
예제 #28
0
 public void RepositoryRecoversFromIncompleteMerge()
 {
     using (var tempRepo = new TemporaryFolder("ChorusIncompleteMerge"))
     {
         var baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
     #if MONO
         baseDir = baseDir.Replace(@"file:", null);
     #else
         baseDir = baseDir.Replace(@"file:\", null);
     #endif
         var zipFile = new ZipFile(Path.Combine(baseDir, Path.Combine("VcsDrivers", Path.Combine("TestData", "incompletemergerepo.zip"))));
         zipFile.ExtractAll(tempRepo.Path);
         var hgRepo = new HgRepository(tempRepo.Path, new NullProgress());
         hgRepo.CheckAndUpdateHgrc();
         var parentFile = tempRepo.GetNewTempFile(true);
         File.WriteAllText(parentFile.Path, "New Content");
         var exception = Assert.Throws<ApplicationException>(() => hgRepo.AddAndCheckinFile(parentFile.Path));
         Assert.That(exception.Message.Contains("Unable to recover") && !exception.Message.Contains("unresolved merge"), "Repository should have conflict in retrying the merge, but not have an incomplete merge");
     }
 }
예제 #29
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.
                        }
                    }
                }
            }
        }