public void RepositoryRecoversFromIncompleteMerge() { using (var tempRepo = new TemporaryFolder("ChorusIncompleteMerge")) { var baseDir = FileUtils.NormalizePath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase)); baseDir = FileUtils.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)); } }
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"); } }
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))); } } }
public override void SetUp() { _tempFolder = new TemporaryFolder("LiftLexEntryRepositoryDeleteIdTransitionTests"); _persistedFilePath = _tempFolder.GetNewTempFile(false); DataMapperUnderTest = new LiftLexEntryRepository(_persistedFilePath.Path); }
public void Setup() { _tempfolder = new TemporaryFolder("LiftLexEntryRepositoryCachingTests"); _tempFile = _tempfolder.GetNewTempFile(true); _repository = new LiftLexEntryRepository(_tempFile.Path); }
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 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. } } } } }
public TestEnvironment(string id1, string id2) { WritingSystemRepository = new TestLdmlInFolderWritingSystemRepository(WritingSystemsPath); _file = _folder.GetNewTempFile(true); File.WriteAllText(_file.Path, String.Format("|{0}||{0}||{1}|", id1, id2)); }