use of org.apache.maven.scm.command.blame.BlameLine in project maven-scm by apache.
the class GitBlameConsumerTest method testConsumerOnNewFile.
/**
* Test what happens if a git-blame command got invoked on a
* file which didn't got added to the git repo yet.
*/
public void testConsumerOnNewFile() throws Exception {
GitBlameConsumer consumer = consumeFile("/src/test/resources/git/blame/git-blame-new-file.out");
Assert.assertEquals(3, consumer.getLines().size());
BlameLine blameLine = consumer.getLines().get(0);
Assert.assertNotNull(blameLine);
Assert.assertEquals("0000000000000000000000000000000000000000", blameLine.getRevision());
Assert.assertEquals("Not Committed Yet", blameLine.getAuthor());
}
use of org.apache.maven.scm.command.blame.BlameLine in project maven-scm by apache.
the class GitBlameConsumerTest method testConsumer.
public void testConsumer() throws Exception {
GitBlameConsumer consumer = consumeFile("/src/test/resources/git/blame/git-blame.out");
Assert.assertEquals(187, consumer.getLines().size());
BlameLine blameLine = consumer.getLines().get(11);
Assert.assertEquals("e670863b2b03e158c59f34af1fee20f91b2bd852", blameLine.getRevision());
Assert.assertEquals("Mark Struberg", blameLine.getAuthor());
Assert.assertNotNull(blameLine.getDate());
}
use of org.apache.maven.scm.command.blame.BlameLine in project maven-scm by apache.
the class GitExeBlameCommandTckTest method verifyResult.
protected void verifyResult(BlameScmResult result) {
List<BlameLine> lines = result.getLines();
assertEquals("Expected 1 line in blame", 1, lines.size());
BlameLine line = lines.get(0);
assertEquals("Mark Struberg", line.getAuthor());
assertEquals("92f139dfec4d1dfb79c3cd2f94e83bf13129668b", line.getRevision());
}
use of org.apache.maven.scm.command.blame.BlameLine in project maven-scm by apache.
the class JGitBlameCommand method executeBlameCommand.
@Override
public BlameScmResult executeBlameCommand(ScmProviderRepository repo, ScmFileSet workingDirectory, String filename) throws ScmException {
Git git = null;
File basedir = workingDirectory.getBasedir();
try {
git = JGitUtils.openRepo(basedir);
BlameResult blameResult = git.blame().setFilePath(filename).call();
List<BlameLine> lines = new ArrayList<BlameLine>();
int i = 0;
while ((i = blameResult.computeNext()) != -1) {
lines.add(new BlameLine(blameResult.getSourceAuthor(i).getWhen(), blameResult.getSourceCommit(i).getName(), blameResult.getSourceAuthor(i).getName(), blameResult.getSourceCommitter(i).getName()));
}
return new BlameScmResult("JGit blame", lines);
} catch (Exception e) {
throw new ScmException("JGit blame failure!", e);
} finally {
JGitUtils.closeRepo(git);
}
}
use of org.apache.maven.scm.command.blame.BlameLine in project maven-scm by apache.
the class AccuRevBlameCommandTest method testBlame.
@Test
public void testBlame() throws Exception {
final File file = new File("src/main/java/Foo.java");
final ScmFileSet testFileSet = new ScmFileSet(basedir, file);
final Date date = new Date();
final BlameLine blameLine = new BlameLine(date, "12", "theAuthor");
when(accurev.annotate(basedir, file)).thenReturn(Collections.singletonList(blameLine));
AccuRevBlameCommand command = new AccuRevBlameCommand(getLogger());
CommandParameters commandParameters = new CommandParameters();
commandParameters.setString(CommandParameter.FILE, file.getPath());
BlameScmResult result = command.blame(repo, testFileSet, commandParameters);
assertThat(result.isSuccess(), is(true));
assertThat(result.getLines().size(), is(1));
assertThat(((BlameLine) result.getLines().get(0)), is(blameLine));
}
Aggregations