Search in sources :

Example 41 with VcsFileRevision

use of com.intellij.openapi.vcs.history.VcsFileRevision in project intellij-community by JetBrains.

the class GitHistoryUtilsTest method testCyclicRename.

// Inspired by IDEA-89347
@Test
public void testCyclicRename() throws Exception {
    List<TestCommit> commits = new ArrayList<>();
    File source = mkdir("source");
    File initialFile = touch("source/PostHighlightingPass.java", "Initial content");
    String initMessage = "Created PostHighlightingPass.java in source";
    addCommit(initMessage);
    String hash = last();
    commits.add(new TestCommit(hash, initMessage, initialFile.getPath()));
    String filePath = initialFile.getPath();
    commits.add(modify(filePath));
    TestCommit commit = move(filePath, mkdir("codeInside-impl"), "Moved from source to codeInside-impl");
    filePath = commit.myPath;
    commits.add(commit);
    commits.add(modify(filePath));
    commit = move(filePath, mkdir("codeInside"), "Moved from codeInside-impl to codeInside");
    filePath = commit.myPath;
    commits.add(commit);
    commits.add(modify(filePath));
    commit = move(filePath, mkdir("lang-impl"), "Moved from codeInside to lang-impl");
    filePath = commit.myPath;
    commits.add(commit);
    commits.add(modify(filePath));
    commit = move(filePath, source, "Moved from lang-impl back to source");
    filePath = commit.myPath;
    commits.add(commit);
    commits.add(modify(filePath));
    commit = move(filePath, mkdir("java"), "Moved from source to java");
    filePath = commit.myPath;
    commits.add(commit);
    commits.add(modify(filePath));
    Collections.reverse(commits);
    VirtualFile vFile = VcsUtil.getVirtualFileWithRefresh(new File(filePath));
    assertNotNull(vFile);
    List<VcsFileRevision> history = GitHistoryUtils.history(myProject, VcsUtil.getFilePath(vFile));
    assertEquals("History size doesn't match. Actual history: \n" + toReadable(history), commits.size(), history.size());
    assertEquals("History is different.", toReadable(commits), toReadable(history));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Test(org.testng.annotations.Test) GitSingleRepoTest(git4idea.test.GitSingleRepoTest)

Example 42 with VcsFileRevision

use of com.intellij.openapi.vcs.history.VcsFileRevision in project intellij-community by JetBrains.

the class GitHistoryUtilsTest method toReadable.

@NotNull
private String toReadable(@NotNull Collection<VcsFileRevision> history) {
    int maxSubjectLength = findMaxLength(history, new Function<VcsFileRevision, String>() {

        @Override
        public String fun(VcsFileRevision revision) {
            return revision.getCommitMessage();
        }
    });
    StringBuilder sb = new StringBuilder();
    for (VcsFileRevision revision : history) {
        GitFileRevision rev = (GitFileRevision) revision;
        String relPath = FileUtil.getRelativePath(new File(myProjectPath), rev.getPath().getIOFile());
        sb.append(String.format("%s  %-" + maxSubjectLength + "s  %s%n", getShortHash(rev.getHash()), rev.getCommitMessage(), relPath));
    }
    return sb.toString();
}
Also used : GitFileRevision(git4idea.GitFileRevision) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 43 with VcsFileRevision

use of com.intellij.openapi.vcs.history.VcsFileRevision in project intellij-community by JetBrains.

the class HgHistoryTest method locallyRenamedFileShouldGetHistory.

@Test
public void locallyRenamedFileShouldGetHistory() throws Exception {
    int versions = 0;
    fillFile(myProjectDir, new String[] { AFILE }, INITIAL_FILE_CONTENT);
    addAll();
    commitAll("initial content");
    versions++;
    fillFile(myProjectDir, new String[] { AFILE }, UPDATED_FILE_CONTENT);
    commitAll("updated content");
    versions++;
    runHgOnProjectRepo("rename", AFILE, BFILE);
    //don't commit 
    refreshVfs();
    ChangeListManager.getInstance(myProject).ensureUpToDate(false);
    final VcsHistorySession session = getHistorySession(BFILE);
    final List<VcsFileRevision> revisions = session.getRevisionList();
    for (VcsFileRevision rev : revisions) {
        rev.loadContent();
    }
    assertEquals(revisions.size(), versions);
    assertTrue(session.isCurrentRevision(revisions.get(0).getRevisionNumber()));
    assertEquals(revisions.get(0).getContent(), UPDATED_FILE_CONTENT.getBytes());
    assertEquals(revisions.get(1).getContent(), INITIAL_FILE_CONTENT.getBytes());
}
Also used : VcsHistorySession(com.intellij.openapi.vcs.history.VcsHistorySession) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) Test(org.testng.annotations.Test)

Example 44 with VcsFileRevision

use of com.intellij.openapi.vcs.history.VcsFileRevision in project intellij-community by JetBrains.

the class HgHistoryTest method renameShouldPreserveFileHistory.

/**
   * 1. Make initial version of a file (create, add, commit).
   * 2. Rename file (rename, commit).
   * 3. Update file (modify, commit).
   * 4. Get the file history.
   * 5. Verify revision contents and the current revision.
   */
@Test
public void renameShouldPreserveFileHistory() throws Exception {
    int versions = 0;
    fillFile(myProjectDir, new String[] { AFILE }, INITIAL_FILE_CONTENT);
    addAll();
    commitAll("initial content");
    versions++;
    runHgOnProjectRepo("rename", AFILE, BFILE);
    commitAll("file renamed");
    versions++;
    fillFile(myProjectDir, new String[] { BFILE }, UPDATED_FILE_CONTENT);
    commitAll("updated content");
    versions++;
    final VcsHistorySession session = getHistorySession(BFILE);
    final List<VcsFileRevision> revisions = session.getRevisionList();
    loadAllRevisions(revisions);
    assertEquals(revisions.size(), versions);
    assertTrue(session.isCurrentRevision(revisions.get(0).getRevisionNumber()));
    assertEquals(revisions.get(0).getContent(), UPDATED_FILE_CONTENT.getBytes());
    assertEquals(revisions.get(2).getContent(), INITIAL_FILE_CONTENT.getBytes());
}
Also used : VcsHistorySession(com.intellij.openapi.vcs.history.VcsHistorySession) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) Test(org.testng.annotations.Test)

Aggregations

VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)44 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 Nullable (org.jetbrains.annotations.Nullable)13 FilePath (com.intellij.openapi.vcs.FilePath)12 Project (com.intellij.openapi.project.Project)10 VcsHistoryProvider (com.intellij.openapi.vcs.history.VcsHistoryProvider)8 VcsHistorySession (com.intellij.openapi.vcs.history.VcsHistorySession)7 VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)7 VcsKey (com.intellij.openapi.vcs.VcsKey)5 VcsAbstractHistorySession (com.intellij.openapi.vcs.history.VcsAbstractHistorySession)5 VcsAppendableHistorySessionPartner (com.intellij.openapi.vcs.history.VcsAppendableHistorySessionPartner)5 Semaphore (com.intellij.util.concurrency.Semaphore)5 GitFileRevision (git4idea.GitFileRevision)5 Test (org.junit.Test)5 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)4 NotNull (org.jetbrains.annotations.NotNull)4 Annotation (com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.Annotation)3 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)3 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)3 HashMap (com.intellij.util.containers.HashMap)3