Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.Repository


        verifyGitRepository();
        return jGitDelegate.getRepository();
    }

    public List<Tag> getTagsOnCommit(String revName) throws GitException, IOException {
        Repository db = getRepository();
        ObjectId commit = db.resolve(revName);
        List<Tag> result = new ArrayList<Tag>();
        if (null != commit) {
            for (final Map.Entry<String, Ref> tag : db.getTags().entrySet()) {
                Ref ref = tag.getValue();
                if (ref.getObjectId().equals(commit)) {
                    result.add(new Tag(tag.getKey(), ref.getObjectId()));
                }
            }
View Full Code Here


        catch (GitAPIException e)
        {
            throw new JGitFlowException(e);
        }

        Repository repo = git.getRepository();
        GitFlowConfiguration gfConfig = new GitFlowConfiguration(git);
        RevWalk walk = null;
        try
        {
            if (!force && gfConfig.gitFlowIsInitialized())
            {
                throw new AlreadyInitializedException("Already initialized for git flow.");
            }

            //First setup master
            if (gfConfig.hasMasterConfigured() && !force)
            {
                context.setMaster(gfConfig.getMaster());
            }
            else
            {
                //if no local master exists, but a remote does, check it out
                if (!GitHelper.localBranchExists(git, context.getMaster()) && GitHelper.remoteBranchExists(git, context.getMaster()))
                {
                    git.branchCreate()
                       .setName(context.getMaster())
                       .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
                       .setStartPoint("origin/" + context.getMaster())
                       .call();
                }
            }

            gfConfig.setMaster(context.getMaster());


            //now setup develop
            if (gfConfig.hasDevelopConfigured() && !force)
            {
                context.setDevelop(gfConfig.getDevelop());
            }

            if (context.getDevelop().equals(context.getMaster()))
            {
                throw new JGitFlowException("master and develop branches cannot be the same: [" + context.getMaster() + "]");
            }

            gfConfig.setDevelop(context.getDevelop());

            //Creation of HEAD
            walk = new RevWalk(repo);
            ObjectId masterBranch = repo.resolve(Constants.R_HEADS + context.getMaster());
            RevCommit masterCommit = null;

            if (null != masterBranch)
            {
                try
                {
                    masterCommit = walk.parseCommit(masterBranch);
                }
                catch (MissingObjectException e)
                {
                    //ignore
                }
                catch (IncorrectObjectTypeException e)
                {
                    //ignore
                }
            }

            if (null == masterCommit)
            {
                RefUpdate refUpdate = repo.getRefDatabase().newUpdate(Constants.HEAD, false);
                refUpdate.setForceUpdate(true);
                refUpdate.link(Constants.R_HEADS + context.getMaster());

                git.commit().setMessage("Initial Commit").call();
            }
View Full Code Here

      if (RepositoryCache.FileKey.isGitRepository(dir, FS.DETECTED))
        rb.setGitDir(dir);
      else
        rb.findGitDir(dir);

      Repository db = rb.build();
      try {
        run(db);
      } finally {
        db.close();
      }
    }
  }
View Full Code Here

      getServletContext().log("Cannot query database", e);
      rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    }

    final Repository repo;
    try {
      repo = repoManager.openRepository(project.getNameKey());
    } catch (RepositoryNotFoundException e) {
      getServletContext().log("Cannot open repository", e);
      rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    }

    final ObjectLoader blobLoader;
    final RevCommit fromCommit;
    final String suffix;
    final String path = patchKey.getFileName();
    try {
      final ObjectReader reader = repo.newObjectReader();
      try {
        final RevWalk rw = new RevWalk(reader);
        final RevCommit c;
        final TreeWalk tw;

        c = rw.parseCommit(ObjectId.fromString(patchSet.getRevision().get()));
        if (side == 0) {
          fromCommit = c;
          suffix = "new";

        } else if (1 <= side && side - 1 < c.getParentCount()) {
          fromCommit = rw.parseCommit(c.getParent(side - 1));
          if (c.getParentCount() == 1) {
            suffix = "old";
          } else {
            suffix = "old" + side;
          }

        } else {
          rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
          return;
        }

        tw = TreeWalk.forPath(reader, path, fromCommit.getTree());
        if (tw == null) {
          rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
          return;
        }

        if (tw.getFileMode(0).getObjectType() == Constants.OBJ_BLOB) {
          blobLoader = reader.open(tw.getObjectId(0), Constants.OBJ_BLOB);

        } else {
          rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
          return;
        }
      } finally {
        reader.release();
      }
    } catch (IOException e) {
      getServletContext().log("Cannot read repository", e);
      rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    } catch (RuntimeException e) {
      getServletContext().log("Cannot read repository", e);
      rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return;
    } finally {
      repo.close();
    }

    final byte[] raw =
        blobLoader.isLarge() ? null : blobLoader.getCachedBytes();
    final long when = fromCommit.getCommitTime() * 1000L;
 
View Full Code Here

      } else {
        git = Git.open(gitRepo);
      }
    } else {
      File gitRepo = stagingDirectory;
      Repository r = null;

      RepositoryBuilder b = new RepositoryBuilder().setGitDir(stagingDirectory).setWorkTree(sourceDirectory);

      if (!gitRepo.exists()) {
        gitRepo.getParentFile().mkdirs();

        r = b.build();

        r.create();
      } else {
        r = b.build();
      }

      git = Git.wrap(r);
View Full Code Here

  }

  @Test
  public void testIndex() {
    // reindex helloworld
    Repository repository = GitBlitSuite.getHelloworldRepository();
    RepositoryModel model = newRepositoryModel(repository);
    lucene.reindex(model, repository);
    repository.close();

    SearchResult result = lucene.search("type:blob AND path:bit.bit", 1, 1, model.name).get(0);
    assertEquals("Mike Donaghy", result.author);
    result = lucene.search("type:blob AND path:clipper.prg", 1, 1, model.name).get(0);
    assertEquals("tinogomes", result.author);

    // reindex JGit
    repository = GitBlitSuite.getJGitRepository();
    model = newRepositoryModel(repository);
    lucene.reindex(model, repository);
    repository.close();
  }
View Full Code Here

  }

  @Test
  public void testQuery() throws Exception {
    // 2 occurrences on the master branch
    Repository repository = GitBlitSuite.getHelloworldRepository();
    RepositoryModel model = newRepositoryModel(repository);
    repository.close();

    List<SearchResult> results = lucene.search("ada", 1, 10, model.name);
    assertEquals(2, results.size());
    for (SearchResult res : results) {
      assertEquals("refs/heads/master", res.branch);
    }

    // author test
    results = lucene.search("author: tinogomes AND type:commit", 1, 10, model.name);
    assertEquals(2, results.size());

    // blob test
    results = lucene.search("type: blob AND \"import std.stdio\"", 1, 10, model.name);
    assertEquals(1, results.size());
    assertEquals("d.D", results.get(0).path);

    // commit test
    repository = GitBlitSuite.getJGitRepository();
    model = newRepositoryModel(repository);
    repository.close();

    results = lucene.search("\"initial jgit contribution to eclipse.org\"", 1, 10, model.name);
    assertEquals(1, results.size());
    assertEquals("Git Development Community", results.get(0).author);
    assertEquals("1a6964c8274c50f0253db75f010d78ef0e739343", results.get(0).commitId);
View Full Code Here

  }

  @Test
  public void testMultiSearch() throws Exception {
    List<String> list = new ArrayList<String>();
    Repository repository = GitBlitSuite.getHelloworldRepository();
    list.add(newRepositoryModel(repository).name);
    repository.close();

    repository = GitBlitSuite.getJGitRepository();
    list.add(newRepositoryModel(repository).name);
    repository.close();

    List<SearchResult> results = lucene.search("test", 1, 10, list);
    assertEquals(10, results.size());
  }
View Full Code Here

  }

  @Test
  public void testDeleteBlobFromIndex() throws Exception {
    // start with a fresh reindex of entire repository
    Repository repository = GitBlitSuite.getHelloworldRepository();
    RepositoryModel model = newRepositoryModel(repository);
    lucene.reindex(model, repository);

    // now delete a blob
    assertTrue(lucene.deleteBlob(model.name, "refs/heads/master", "java.java"));
View Full Code Here

    assertTrue("Repository list is empty!", repositories.size() > 0);
    assertTrue(
        "Missing Helloworld repository!",
        repositories.contains(GitBlitSuite.getHelloworldRepository().getDirectory()
            .getName()));
    Repository r = GitBlitSuite.getHelloworldRepository();
    RepositoryModel model = repositories().getRepositoryModel(r.getDirectory().getName());
    assertTrue("Helloworld model is null!", model != null);
    assertEquals(GitBlitSuite.getHelloworldRepository().getDirectory().getName(), model.name);
    assertTrue(repositories().updateLastChangeFields(r, model) > 22000L);
    r.close();
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.lib.Repository

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.