コード例 #1
0
  /**
   * 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}, FILE_CONTENT);
    addAll();
    commitAll("initial content");
    versions++;

    runHgOnProjectRepo("rename", AFILE, BFILE);
    commitAll("file renamed");
    versions++;

    fillFile(myProjectDir, new String[] {BFILE}, FILE_CONTENT_2);
    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(), FILE_CONTENT_2.getBytes());
    assertEquals(revisions.get(2).getContent(), FILE_CONTENT.getBytes());
  }
コード例 #2
0
  @Nullable
  private byte[] loadFromVersionControl(long date, VirtualFile f) {
    try {
      final AbstractVcs vcs = VcsUtil.getVcsFor(myProject, f);
      if (vcs == null) return null;

      final VcsHistoryProvider historyProvider = vcs.getVcsHistoryProvider();
      if (historyProvider == null) return null;

      final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(f);
      final VcsHistorySession session = historyProvider.createSessionFor(filePath);
      if (session == null) return null;

      final List<VcsFileRevision> list = session.getRevisionList();

      if (list != null) {
        for (VcsFileRevision revision : list) {
          final Date revisionDate = revision.getRevisionDate();
          if (revisionDate == null) {
            return null;
          }

          if (revisionDate.getTime() < date) {
            return revision.loadContent();
          }
        }
      }
    } catch (Exception e) {
      LOG.info(e);
      return null;
    }
    return null;
  }
コード例 #3
0
  /**
   * 1. Make two versions of a file (create, add, commit, modify, commit). 2. Get the revisions
   * history. 3. Verify versions' contents and the current version.
   */
  @Test
  public void testCurrentAndPreviousRevisions() throws Exception {
    int versions = 0;
    fillFile(myProjectDir, new String[] {AFILE}, FILE_CONTENT);
    addAll();
    commitAll("initial content");
    versions++;
    fillFile(myProjectDir, new String[] {AFILE}, FILE_CONTENT_2);
    commitAll("updated content");
    versions++;

    final VcsHistorySession session = getHistorySession(AFILE);
    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(), FILE_CONTENT_2.getBytes());
    assertEquals(revisions.get(1).getContent(), FILE_CONTENT.getBytes());
  }