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));
}
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();
}
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());
}
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());
}
Aggregations