public void ChangeLogFromHgRepositoryAreAccurate() { const string repositoryName = "changeLog"; using (TestRepository testRepository = GetRepository(repositoryName)) { // Arrange string helloTextPath = Path.Combine(testRepository.PhysicalPath, "Hello.txt"); var hgRepo = new HgRepository(testRepository.PhysicalPath, "", new MockDeploymentSettingsManager(), NullTracerFactory.Instance); // Act hgRepo.Initialize(); File.WriteAllText(helloTextPath, "Hello world"); hgRepo.AddFile(helloTextPath); hgRepo.Commit("First commit"); File.AppendAllText(helloTextPath, "Hello again"); hgRepo.Commit("Second commit"); List <ChangeSet> changes = hgRepo.GetChanges().ToList(); // Assert - 1 Assert.Equal(2, changes.Count()); var lastChange = changes[0]; Assert.Equal("Second commit", lastChange.Message); } }
/// <summary> /// Do a no-op merge. (See: http://mercurial.selenic.com/wiki/PruningDeadBranches#No-Op_Merges) /// </summary> private void NoopMerge(HgRepository repo, Revision keeperRevision, Revision gonerRevision) { string optionalComment = null; using (var optionalCommentDlg = new OptionalCommentDlg()) { if (optionalCommentDlg.ShowDialog(this) == DialogResult.OK && !string.IsNullOrWhiteSpace(optionalCommentDlg.OptionalComment)) { optionalComment = optionalCommentDlg.OptionalComment.Trim(); } } // Merge goner into keeper. repo.Merge(_repoFolder, gonerRevision.Number.LocalRevisionNumber); // Revert the merge. repo.Execute(repo.SecondsBeforeTimeoutOnMergeOperation, "revert", "-a", "-r", keeperRevision.Number.LocalRevisionNumber); // Commit var comment = string.Format(@"No-Op Merge: Revert repository to revision '{0}'", keeperRevision.Number.LocalRevisionNumber); if (!string.IsNullOrWhiteSpace(optionalComment)) { comment = string.Format(@"{0}. {1}", comment, optionalComment); } repo.Commit(true, comment); }
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); }
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); }
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); } } }
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); } } }
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); } }
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); } }
/// <summary> /// Do a no-op merge. (See: http://mercurial.selenic.com/wiki/PruningDeadBranches#No-Op_Merges) /// </summary> private void NoopMerge(HgRepository repo, Revision keeperRevision, Revision gonerRevision) { string optionalComment = null; using (var optionalCommentDlg = new OptionalCommentDlg()) { if (optionalCommentDlg.ShowDialog(this) == DialogResult.OK && !string.IsNullOrWhiteSpace(optionalCommentDlg.OptionalComment)) { optionalComment = optionalCommentDlg.OptionalComment.Trim(); } } // Merge goner into keeper. repo.Merge(_repoFolder, gonerRevision.Number.LocalRevisionNumber); // Revert the merge. repo.Execute(repo.SecondsBeforeTimeoutOnMergeOperation, "revert", "-a", "-r", keeperRevision.Number.LocalRevisionNumber); // Commit var comment = string.Format(@"No-Op Merge: Revert repository to revision '{0}'", keeperRevision.Number.LocalRevisionNumber); if (!string.IsNullOrWhiteSpace(optionalComment)) comment = string.Format(@"{0}. {1}", comment, optionalComment); repo.Commit(true, comment); }
public void ChangeAndCheckinFile(string path, string contents) { File.WriteAllText(path, contents); Repository.Commit(false, "{0}-->{1}", Path.GetFileName(path), contents); }
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")); } } } }