use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.
the class JGitUtilsTest method testDocuments.
@Test
public void testDocuments() throws Exception {
Repository repository = GitBlitSuite.getTicgitRepository();
List<String> extensions = Arrays.asList(new String[] { ".mkd", ".md" });
List<PathModel> markdownDocs = JGitUtils.getDocuments(repository, extensions);
List<PathModel> allFiles = JGitUtils.getDocuments(repository, null);
repository.close();
assertTrue(markdownDocs.size() > 0);
assertTrue(allFiles.size() > markdownDocs.size());
}
use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.
the class JGitUtilsTest method testStringContent.
@Test
public void testStringContent() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository();
String contentA = JGitUtils.getStringContent(repository, (RevTree) null, "java.java");
RevCommit commit = JGitUtils.getCommit(repository, Constants.HEAD);
String contentB = JGitUtils.getStringContent(repository, commit.getTree(), "java.java");
assertTrue("ContentA is null!", contentA != null && contentA.length() > 0);
assertTrue("ContentB is null!", contentB != null && contentB.length() > 0);
assertTrue(contentA.equals(contentB));
String contentC = JGitUtils.getStringContent(repository, commit.getTree(), "missing.txt");
// manually construct a blob, calculate the hash, lookup the hash in git
StringBuilder sb = new StringBuilder();
sb.append("blob ").append(contentA.length()).append('\0');
sb.append(contentA);
String sha1 = StringUtils.getSHA1(sb.toString());
String contentD = JGitUtils.getStringContent(repository, sha1);
repository.close();
assertNull(contentC);
assertTrue(contentA.equals(contentD));
}
use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.
the class JGitUtilsTest method testPlots.
@Test
public void testPlots() throws Exception {
Repository repository = GitBlitSuite.getTicgitRepository();
PlotWalk pw = new PlotWalk(repository);
PlotCommitList<PlotLane> commits = new PlotCommitList<PlotLane>();
commits.source(pw);
commits.fillTo(25);
for (PlotCommit<PlotLane> commit : commits) {
System.out.println(commit);
}
repository.close();
}
use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.
the class BranchesPanel method createDeleteBranchLink.
private Link<Void> createDeleteBranchLink(final RepositoryModel repositoryModel, final RefModel entry) {
Link<Void> deleteLink = new Link<Void>("deleteBranch") {
private static final long serialVersionUID = 1L;
@Override
public void onClick() {
Repository r = app().repositories().getRepository(repositoryModel.name);
if (r == null) {
if (app().repositories().isCollectingGarbage(repositoryModel.name)) {
error(MessageFormat.format(getString("gb.busyCollectingGarbage"), repositoryModel.name));
} else {
error(MessageFormat.format("Failed to find repository {0}", repositoryModel.name));
}
return;
}
final String branch = entry.getName();
Ref ref = null;
try {
ref = r.getRef(branch);
if (ref == null && !branch.startsWith(Constants.R_HEADS)) {
ref = r.getRef(Constants.R_HEADS + branch);
}
} catch (IOException e) {
}
if (ref != null) {
boolean success = JGitUtils.deleteBranchRef(r, ref.getName());
if (success) {
// clear commit cache
CommitCache.instance().clear(repositoryModel.name, branch);
// optionally update reflog
if (RefLogUtils.hasRefLogBranch(r)) {
UserModel user = GitBlitWebSession.get().getUser();
RefLogUtils.deleteRef(user, r, ref);
}
}
if (success) {
info(MessageFormat.format("Branch \"{0}\" deleted", branch));
} else {
error(MessageFormat.format("Failed to delete branch \"{0}\"", branch));
}
}
r.close();
// redirect to the owning page
PageParameters params = WicketUtils.newRepositoryParameter(repositoryModel.name);
String relativeUrl = urlFor(getPage().getClass(), params).toString();
String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
}
};
deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format("Delete branch \"{0}\"?", entry.displayName)));
return deleteLink;
}
use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.
the class DiffUtilsTest method testArbitraryCommitDiff.
@Test
public void testArbitraryCommitDiff() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository();
RevCommit baseCommit = JGitUtils.getCommit(repository, "8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
RevCommit commit = JGitUtils.getCommit(repository, "1d0c2933a4ae69c362f76797d42d6bd182d05176");
String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content;
repository.close();
assertTrue(diff != null && diff.length() > 0);
String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
assertTrue(diff.indexOf(expected) > -1);
}
Aggregations