Search in sources :

Example 1 with HgAnnotateCommand

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

the class HgAnnotationTest method testAnnotationWithVerboseOption.

public void testAnnotationWithVerboseOption() throws VcsException {
    myRepository.refresh(false, true);
    final VirtualFile file = myRepository.findFileByRelativePath(firstCreatedFile);
    assert file != null;
    List<String> users = Arrays.asList(defaultAuthor, author1, author2);
    final HgFile hgFile = new HgFile(myRepository, VfsUtilCore.virtualToIoFile(file));
    final String date = DateFormatUtil.formatPrettyDate(Clock.getTime());
    List<HgAnnotationLine> annotationLines = new HgAnnotateCommand(myProject).execute(hgFile, null);
    for (int i = 0; i < annotationLines.size(); ++i) {
        HgAnnotationLine line = annotationLines.get(i);
        assertEquals(users.get(i), line.get(HgAnnotation.FIELD.USER));
        assertEquals(date, line.get(HgAnnotation.FIELD.DATE));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) HgAnnotationLine(org.zmlx.hg4idea.provider.annotate.HgAnnotationLine) HgAnnotateCommand(org.zmlx.hg4idea.command.HgAnnotateCommand)

Example 2 with HgAnnotateCommand

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

the class HgAnnotationProvider method annotate.

@NotNull
public FileAnnotation annotate(@NotNull VirtualFile file, VcsFileRevision revision) throws VcsException {
    final VirtualFile vcsRoot = VcsUtil.getVcsRootFor(myProject, VcsUtil.getFilePath(file.getPath()));
    if (vcsRoot == null) {
        throw new VcsException("vcs root is null for " + file);
    }
    HgRevisionNumber revisionNumber = revision != null ? (HgRevisionNumber) revision.getRevisionNumber() : null;
    final HgFile hgFile = new HgFile(vcsRoot, VfsUtilCore.virtualToIoFile(file));
    HgFile fileToAnnotate = revision instanceof HgFileRevision ? HgUtil.getFileNameInTargetRevision(myProject, revisionNumber, hgFile) : new HgFile(vcsRoot, HgUtil.getOriginalFileName(hgFile.toFilePath(), ChangeListManager.getInstance(myProject)));
    final List<HgAnnotationLine> annotationResult = (new HgAnnotateCommand(myProject)).execute(fileToAnnotate, revisionNumber);
    //for uncommitted renamed file we should provide local name otherwise --follow will fail
    final List<HgFileRevision> logResult = HgHistoryProvider.getHistory(revision == null ? hgFile.toFilePath() : fileToAnnotate.toFilePath(), vcsRoot, myProject, null, -1);
    return new HgAnnotation(myProject, hgFile, annotationResult, logResult, revisionNumber != null ? revisionNumber : new HgWorkingCopyRevisionsCommand(myProject).tip(vcsRoot));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) HgFileRevision(org.zmlx.hg4idea.HgFileRevision) VcsException(com.intellij.openapi.vcs.VcsException) HgAnnotateCommand(org.zmlx.hg4idea.command.HgAnnotateCommand) HgWorkingCopyRevisionsCommand(org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with HgAnnotateCommand

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

the class HgAnnotationProvider method annotate.

@NotNull
@Override
public FileAnnotation annotate(@NotNull FilePath path, @NotNull VcsRevisionNumber revision) throws VcsException {
    final VirtualFile vcsRoot = VcsUtil.getVcsRootFor(myProject, path);
    if (vcsRoot == null) {
        throw new VcsException("vcs root is null for " + path);
    }
    final HgFile hgFile = new HgFile(vcsRoot, path);
    final List<HgAnnotationLine> annotationResult = (new HgAnnotateCommand(myProject)).execute(hgFile, (HgRevisionNumber) revision);
    final List<HgFileRevision> logResult = HgHistoryProvider.getHistory(hgFile.toFilePath(), vcsRoot, myProject, (HgRevisionNumber) revision, -1);
    return new HgAnnotation(myProject, hgFile, annotationResult, logResult, revision);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) HgFileRevision(org.zmlx.hg4idea.HgFileRevision) VcsException(com.intellij.openapi.vcs.VcsException) HgAnnotateCommand(org.zmlx.hg4idea.command.HgAnnotateCommand) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with HgAnnotateCommand

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

the class HgAnnotationTest method annotationWithWhitespaceOption.

private void annotationWithWhitespaceOption(boolean ignoreWhitespaces) {
    cd(myRepository);
    String whitespaceFile = "whitespaces.txt";
    touch(whitespaceFile, "not whitespaces");
    myRepository.refresh(false, true);
    String whiteSpaceAuthor = "Mr.Whitespace";
    final VirtualFile file = myRepository.findFileByRelativePath(whitespaceFile);
    assert file != null;
    hg("add " + whitespaceFile);
    hg("commit -m modify -u '" + defaultAuthor + "'");
    //add several whitespaces
    echo(whitespaceFile, "    ");
    hg("commit -m whitespaces -u '" + whiteSpaceAuthor + "'");
    final HgFile hgFile = new HgFile(myRepository, VfsUtilCore.virtualToIoFile(file));
    myVcs.getProjectSettings().setIgnoreWhitespacesInAnnotations(ignoreWhitespaces);
    List<HgAnnotationLine> annotationLines = new HgAnnotateCommand(myProject).execute(hgFile, null);
    HgAnnotationLine line = annotationLines.get(0);
    assertEquals(ignoreWhitespaces ? defaultAuthor : whiteSpaceAuthor, line.get(HgAnnotation.FIELD.USER));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) HgAnnotationLine(org.zmlx.hg4idea.provider.annotate.HgAnnotationLine) HgAnnotateCommand(org.zmlx.hg4idea.command.HgAnnotateCommand)

Example 5 with HgAnnotateCommand

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

the class HgAnnotateCommandTest method testParse.

@Test(dataProvider = "annotate_output")
public void testParse(String fileName, String annotationNativeOutput) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    HgAnnotateCommand command = new HgAnnotateCommand(myProject);
    Method parseMethod = HgAnnotateCommand.class.getDeclaredMethod("parse", List.class);
    parseMethod.setAccessible(true);
    List<String> annotations = Arrays.asList(annotationNativeOutput.split("(\n|\r|\r\n)"));
    List<HgAnnotationLine> result = (List<HgAnnotationLine>) parseMethod.invoke(command, annotations);
    assertEquals(result, myAnnotations);
}
Also used : HgAnnotationLine(org.zmlx.hg4idea.provider.annotate.HgAnnotationLine) HgAnnotateCommand(org.zmlx.hg4idea.command.HgAnnotateCommand) ArrayList(java.util.ArrayList) List(java.util.List) BeforeMethod(org.testng.annotations.BeforeMethod) Method(java.lang.reflect.Method) Test(org.testng.annotations.Test)

Aggregations

HgAnnotateCommand (org.zmlx.hg4idea.command.HgAnnotateCommand)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 HgFile (org.zmlx.hg4idea.HgFile)4 HgAnnotationLine (org.zmlx.hg4idea.provider.annotate.HgAnnotationLine)3 VcsException (com.intellij.openapi.vcs.VcsException)2 NotNull (org.jetbrains.annotations.NotNull)2 HgFileRevision (org.zmlx.hg4idea.HgFileRevision)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 Test (org.testng.annotations.Test)1 HgRevisionNumber (org.zmlx.hg4idea.HgRevisionNumber)1 HgWorkingCopyRevisionsCommand (org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand)1