Search in sources :

Example 41 with Repository

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());
}
Also used : Repository(org.eclipse.jgit.lib.Repository) PathModel(com.gitblit.models.PathModel) Test(org.junit.Test)

Example 42 with Repository

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));
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 43 with Repository

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();
}
Also used : Repository(org.eclipse.jgit.lib.Repository) PlotLane(org.eclipse.jgit.revplot.PlotLane) PlotCommitList(org.eclipse.jgit.revplot.PlotCommitList) PlotWalk(org.eclipse.jgit.revplot.PlotWalk) Test(org.junit.Test)

Example 44 with Repository

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;
}
Also used : UserModel(com.gitblit.models.UserModel) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) RedirectRequestTarget(org.apache.wicket.request.target.basic.RedirectRequestTarget) IOException(java.io.IOException) PageParameters(org.apache.wicket.PageParameters) ExternalLink(org.apache.wicket.markup.html.link.ExternalLink) Link(org.apache.wicket.markup.html.link.Link) BookmarkablePageLink(org.apache.wicket.markup.html.link.BookmarkablePageLink)

Example 45 with Repository

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);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

Repository (org.eclipse.jgit.lib.Repository)326 IOException (java.io.IOException)103 RevWalk (org.eclipse.jgit.revwalk.RevWalk)102 Test (org.junit.Test)81 RevCommit (org.eclipse.jgit.revwalk.RevCommit)76 ObjectId (org.eclipse.jgit.lib.ObjectId)72 File (java.io.File)43 TestRepository (org.eclipse.jgit.junit.TestRepository)40 Change (com.google.gerrit.reviewdb.client.Change)39 OrmException (com.google.gwtorm.server.OrmException)39 Ref (org.eclipse.jgit.lib.Ref)35 Project (com.google.gerrit.reviewdb.client.Project)32 ArrayList (java.util.ArrayList)31 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)27 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)26 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)24 Map (java.util.Map)23 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)23 RepositoryModel (com.gitblit.models.RepositoryModel)20 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)20