Search in sources :

Example 1 with HgRevisionNumber

use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.

the class HgAnnotationTest method checkAnnotation.

private void checkAnnotation(String name, String revisionNum, String expectedContent) throws VcsException {
    FileAnnotation fileAnnotation = myHgAnnotationProvider.annotate(VcsUtil.getFilePath(new File(myRepository.getPath(), name)), HgRevisionNumber.getInstance(revisionNum, revisionNum));
    final HgRevisionNumber actualRevisionNumber = (HgRevisionNumber) fileAnnotation.getLineRevisionNumber(0);
    assert actualRevisionNumber != null;
    assertEquals(revisionNum, actualRevisionNumber.getRevision());
    assertEquals(expectedContent, fileAnnotation.getAnnotatedContent());
}
Also used : HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) File(java.io.File)

Example 2 with HgRevisionNumber

use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.

the class HgCompareWithBranchAction method getDiffChanges.

@Override
@NotNull
protected Collection<Change> getDiffChanges(@NotNull Project project, @NotNull VirtualFile file, @NotNull String branchToCompare) throws VcsException {
    HgRepository repository = getRepositoryManager(project).getRepositoryForFile(file);
    if (repository == null) {
        throw new VcsException("Couldn't find repository for " + file.getName());
    }
    final FilePath filePath = VcsUtil.getFilePath(file);
    final VirtualFile repositoryRoot = repository.getRoot();
    final HgFile hgFile = new HgFile(repositoryRoot, filePath);
    Hash refHashToCompare = detectActiveHashByName(repository, branchToCompare);
    if (refHashToCompare == null) {
        throw new VcsException(String.format("Couldn't detect commit related to %s name for %s.", branchToCompare, file));
    }
    final HgRevisionNumber compareWithRevisionNumber = HgRevisionNumber.getInstance(branchToCompare, refHashToCompare.toString());
    List<Change> changes = HgUtil.getDiff(project, repositoryRoot, filePath, compareWithRevisionNumber, null);
    if (changes.isEmpty() && !existInBranch(repository, filePath, compareWithRevisionNumber)) {
        throw new VcsException(fileDoesntExistInBranchError(file, branchToCompare));
    }
    return changes.isEmpty() && !filePath.isDirectory() ? createChangesWithCurrentContentForFile(filePath, HgContentRevision.create(project, hgFile, compareWithRevisionNumber)) : changes;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) VcsException(com.intellij.openapi.vcs.VcsException) HgRepository(org.zmlx.hg4idea.repo.HgRepository) Change(com.intellij.openapi.vcs.changes.Change) Hash(com.intellij.vcs.log.Hash) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with HgRevisionNumber

use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.

the class HgUpdateTest method assertCurrentHeadIsMerge.

private void assertCurrentHeadIsMerge(HgRevisionNumber incomingHead, HgRevisionNumber headBeforeUpdate) {
    List<HgRevisionNumber> newHeads = new HgHeadsCommand(myProject, projectRepoVirtualFile).executeInCurrentThread();
    assertEquals(newHeads.size(), 1, "After updating, there should be only one head because the remote heads should have been merged");
    HgRevisionNumber newHead = newHeads.get(0);
    HgParentsCommand parents = new HgParentsCommand(myProject);
    parents.setRevision(newHead);
    List<HgRevisionNumber> parentRevisions = parents.executeInCurrentThread(projectRepoVirtualFile);
    assertEquals(parentRevisions.size(), 2);
    assertTrue(parentRevisions.contains(incomingHead));
    assertTrue(parentRevisions.contains(headBeforeUpdate));
}
Also used : HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber)

Example 4 with HgRevisionNumber

use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.

the class HgUpdateTest method updateKeepsWorkingAfterPull.

@Test
public void updateKeepsWorkingAfterPull() throws Exception {
    changeFile_A_AndCommitInRemoteRepository();
    //do a simple pull without an update
    HgPullCommand pull = new HgPullCommand(myProject, projectRepoVirtualFile);
    pull.setSource(HgUtil.getRepositoryDefaultPath(myProject, projectRepoVirtualFile));
    pull.executeInCurrentThread();
    assertEquals(determineNumberOfIncomingChanges(projectRepo), 0, "The update operation should have pulled the incoming changes from the default repository.");
    updateThroughPlugin();
    HgRevisionNumber parentRevision = new HgWorkingCopyRevisionsCommand(myProject).firstParent(projectRepoVirtualFile);
    assertEquals(parentRevision.getRevision(), "1", "The working directory should have been updated to the latest version");
}
Also used : HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) Test(org.testng.annotations.Test)

Example 5 with HgRevisionNumber

use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.

the class HgUpdateTest method updateShouldMergeButNotCommitWithConflicts.

@Test
public void updateShouldMergeButNotCommitWithConflicts() throws Exception {
    changeFile_A_AndCommitInRemoteRepository();
    VirtualFile commonFile = projectRepoVirtualFile.findChild("com").findChild("a.txt");
    assertNotNull(commonFile);
    VcsTestUtil.editFileInCommand(myProject, commonFile, "conflicting content");
    runHg(projectRepo, "commit", "-m", "adding conflicting history to local repository");
    PreUpdateInformation preUpdateInformation = new PreUpdateInformation().getPreUpdateInformation();
    HgRevisionNumber incomingHead = preUpdateInformation.getIncomingHead();
    HgRevisionNumber headBeforeUpdate = preUpdateInformation.getHeadBeforeUpdate();
    List<VcsException> warnings = updateThroughPlugin();
    assertFalse(warnings.isEmpty());
    assertTrue(warnings.get(warnings.size() - 1).getMessage().contains("conflicts"));
    assertTrue(warnings.get(warnings.size() - 1).getMessage().contains("commit"));
    List<HgRevisionNumber> parents = new HgWorkingCopyRevisionsCommand(myProject).parents(projectRepoVirtualFile);
    assertEquals(parents.size(), 2);
    assertTrue(parents.contains(incomingHead));
    assertTrue(parents.contains(headBeforeUpdate));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) VcsException(com.intellij.openapi.vcs.VcsException) Test(org.testng.annotations.Test)

Aggregations

HgRevisionNumber (org.zmlx.hg4idea.HgRevisionNumber)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 Test (org.testng.annotations.Test)8 HgFile (org.zmlx.hg4idea.HgFile)6 VcsException (com.intellij.openapi.vcs.VcsException)5 NotNull (org.jetbrains.annotations.NotNull)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 HgWorkingCopyRevisionsCommand (org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand)4 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)4 FilePath (com.intellij.openapi.vcs.FilePath)3 HgFileRevision (org.zmlx.hg4idea.HgFileRevision)3 Change (com.intellij.openapi.vcs.changes.Change)2 ItemLatestState (com.intellij.openapi.vcs.diff.ItemLatestState)2 Nullable (org.jetbrains.annotations.Nullable)2 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)1 MergeData (com.intellij.openapi.vcs.merge.MergeData)1 SmartList (com.intellij.util.SmartList)1 Hash (com.intellij.vcs.log.Hash)1 VcsRunnable (com.intellij.vcsUtil.VcsRunnable)1