public void testChangeSet() { ArrayList<String> lines = new ArrayList<String>(); lines.add("Some header junk we should ignore..."); lines.add("header line 2"); lines.add("commit 123abc456def"); lines.add("tree 789ghi012jkl"); lines.add("parent 345mno678pqr"); lines.add("author John Author <*****@*****.**> 1234567 -0600"); lines.add("commiter John Committer <*****@*****.**> 1234567 -0600"); lines.add(""); lines.add(" Commit title."); lines.add(" Commit extended description."); lines.add(""); lines.add( ":000000 123456 0000000000000000000000000000000000000000 123abc456def789abc012def345abc678def901a A\tsrc/test/add.file"); lines.add( ":123456 000000 123abc456def789abc012def345abc678def901a 0000000000000000000000000000000000000000 D\tsrc/test/deleted.file"); lines.add( ":123456 789012 123abc456def789abc012def345abc678def901a bc234def567abc890def123abc456def789abc01 M\tsrc/test/modified.file"); lines.add( ":123456 789012 123abc456def789abc012def345abc678def901a bc234def567abc890def123abc456def789abc01 R012\tsrc/test/renamedFrom.file\tsrc/test/renamedTo.file"); GitChangeSet changeSet = new GitChangeSet(lines); Assert.assertEquals("123abc456def", changeSet.getId()); Assert.assertEquals("Commit title.", changeSet.getMsg()); Assert.assertEquals("Commit title.\nCommit extended description.\n", changeSet.getComment()); HashSet<String> expectedAffectedPaths = new HashSet<String>(7); expectedAffectedPaths.add("src/test/add.file"); expectedAffectedPaths.add("src/test/deleted.file"); expectedAffectedPaths.add("src/test/modified.file"); expectedAffectedPaths.add("src/test/renamedFrom.file\tsrc/test/renamedTo.file"); Assert.assertEquals(expectedAffectedPaths, changeSet.getAffectedPaths()); Collection<Path> actualPaths = changeSet.getPaths(); Assert.assertEquals(4, actualPaths.size()); for (Path path : actualPaths) { if ("src/test/add.file".equals(path.getPath())) { Assert.assertEquals(EditType.ADD, path.getEditType()); Assert.assertNull(path.getSrc()); Assert.assertEquals("123abc456def789abc012def345abc678def901a", path.getDst()); } else if ("src/test/deleted.file".equals(path.getPath())) { Assert.assertEquals(EditType.DELETE, path.getEditType()); Assert.assertEquals("123abc456def789abc012def345abc678def901a", path.getSrc()); Assert.assertNull(path.getDst()); } else if ("src/test/modified.file".equals(path.getPath())) { Assert.assertEquals(EditType.EDIT, path.getEditType()); Assert.assertEquals("123abc456def789abc012def345abc678def901a", path.getSrc()); Assert.assertEquals("bc234def567abc890def123abc456def789abc01", path.getDst()); } else if ("src/test/renamedFrom.file\tsrc/test/renamedTo.file".equals(path.getPath())) { Assert.assertEquals(EditType.EDIT, path.getEditType()); Assert.assertNull(path.getSrc()); Assert.assertNull(path.getDst()); } else { Assert.fail("Unrecognized path."); } } }
/** * Creates a link to the commit diff. * * <p>https://[Gitorious * URL]/commit/a9182a07750c9a0dfd89a8461adf72ef5ef0885b/diffs?diffmode=sidebyside&fragment=1#[path * to file] * * @param path * @return diff link * @throws IOException */ @Override public URL getDiffLink(Path path) throws IOException { final GitChangeSet changeSet = path.getChangeSet(); return new URL( url, "commit/" + changeSet.getId().toString() + "/diffs?diffmode=sidebyside&fragment=1#" + path.getPath()); }
/** * Creates a link to the file diff. http://[GitWeb * URL]?a=blobdiff;f=[path];fp=[path];h=[dst];hp=[src];hb=[commit];hpb=[parent commit] * * @param path affected file path * @return diff link * @throws IOException */ @Override public URL getDiffLink(Path path) throws IOException { if (path.getEditType() != EditType.EDIT || path.getSrc() == null || path.getDst() == null || path.getChangeSet().getParentCommit() == null) { return null; } GitChangeSet changeSet = path.getChangeSet(); String spec = param() .add("a=blobdiff") .add("f=" + path.getPath()) .add("fp=" + path.getPath()) .add("h=" + path.getSrc()) .add("hp=" + path.getDst()) .add("hb=" + changeSet.getId()) .add("hpb=" + changeSet.getParentCommit()) .toString(); return new URL(url, url.getPath() + spec); }
@Test public void testGetId() { assertEquals(id, changeSet.getId()); }
@Override public URL getChangeSetLink(GitChangeSet changeSet) throws IOException { return new URL(url, "commit/" + changeSet.getId().toString()); }
@Override public URL getChangeSetLink(GitChangeSet changeSet) throws IOException { return new URL( url, url.getPath() + param().add("a=commit").add("h=" + changeSet.getId()).toString()); }