Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.Repository


    configure(clone);
    clone.setDirectory(moduleDirectory);
    clone.setURI(resolvedUri);
    if (monitor != null)
      clone.setProgressMonitor(monitor);
    Repository subRepo = clone.call().getRepository();

    // Save submodule URL to parent repository's config
    StoredConfig config = repo.getConfig();
    config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
        ConfigConstants.CONFIG_KEY_URL, resolvedUri);
View Full Code Here


   *
   * @return object id of HEAD reference
   * @throws IOException
   */
  public ObjectId getHead() throws IOException {
    Repository subRepo = getRepository();
    return subRepo != null ? subRepo.resolve(Constants.HEAD) : null;
  }
View Full Code Here

   *
   * @return ref name, null on failures
   * @throws IOException
   */
  public String getHeadRef() throws IOException {
    Repository subRepo = getRepository();
    if (subRepo == null)
      return null;
    Ref head = subRepo.getRef(Constants.HEAD);
    return head != null ? head.getLeaf().getName() : null;
  }
View Full Code Here

        String path = generator.getPath();
        config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION,
            path, ConfigConstants.CONFIG_KEY_URL, remoteUrl);
        synced.put(path, remoteUrl);

        Repository subRepo = generator.getRepository();
        if (subRepo == null)
          continue;

        StoredConfig subConfig = subRepo.getConfig();
        // Get name of remote associated with current branch and
        // fall back to default remote name as last resort
        String branch = getHeadBranch(subRepo);
        String remote = null;
        if (branch != null)
View Full Code Here

          + ") is not a git repository.");
    }

    AddCommand gitAdd;
    try {
      Repository repo = new FileRepositoryBuilder().readEnvironment()
          .findGitDir(src).build();
      gitAdd = new Git(repo).add();
    } catch (IOException e) {
      throw new BuildException("Could not access repository " + src, e);
    }
View Full Code Here

  @Override
  public void execute() throws BuildException {
    CheckoutCommand checkout;
    try {
      Repository repo = new FileRepositoryBuilder().readEnvironment()
          .findGitDir(src).build();
      checkout = new Git(repo).checkout();
    } catch (IOException e) {
      throw new BuildException("Could not access repository " + src, e);
    }
View Full Code Here

   public static CherryPickResult cherryPickNoMerge(final Git git, Ref src) throws GitAPIException,
            CantMergeCommitWithZeroParentsException
   {
      // Does the same as the original git-cherryPick
      // except commiting after running merger
      Repository repo = git.getRepository();

      RevCommit newHead = null;
      List<Ref> cherryPickedRefs = new LinkedList<Ref>();

      RevWalk revWalk = new RevWalk(repo);
      try
      {
         // get the head commit
         Ref headRef = repo.getRef(Constants.HEAD);
         if (headRef == null)
            throw new NoHeadException(
                     JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
         RevCommit headCommit = revWalk.parseCommit(headRef.getObjectId());

         newHead = headCommit;

         // get the commit to be cherry-picked
         // handle annotated tags
         ObjectId srcObjectId = src.getPeeledObjectId();
         if (srcObjectId == null)
            srcObjectId = src.getObjectId();
         RevCommit srcCommit = revWalk.parseCommit(srcObjectId);

         // get the parent of the commit to cherry-pick
         if (srcCommit.getParentCount() == 0)
            throw new CantMergeCommitWithZeroParentsException("Commit with zero parents cannot be merged");

         if (srcCommit.getParentCount() > 1)
            throw new MultipleParentsNotAllowedException(
                     MessageFormat.format(
                              JGitText.get().canOnlyCherryPickCommitsWithOneParent,
                              srcCommit.name(),
                              Integer.valueOf(srcCommit.getParentCount())));

         RevCommit srcParent = srcCommit.getParent(0);
         revWalk.parseHeaders(srcParent);

         ResolveMerger merger = (ResolveMerger) MergeStrategy.RESOLVE
                  .newMerger(repo);
         merger.setWorkingTreeIterator(new FileTreeIterator(repo));
         merger.setBase(srcParent.getTree());
         if (merger.merge(headCommit, srcCommit))
         {
            DirCacheCheckout dco = new DirCacheCheckout(repo,
                     headCommit.getTree(), repo.lockDirCache(),
                     merger.getResultTreeId());
            dco.setFailOnConflict(true);
            dco.checkout();

            cherryPickedRefs.add(src);
         }
         else
         {
            if (merger.failed())
               return new CherryPickResult(merger.getFailingPaths());

            // there are merge conflicts
            String message = new MergeMessageFormatter()
                     .formatWithConflicts(srcCommit.getFullMessage(),
                              merger.getUnmergedPaths());

            repo.writeCherryPickHead(srcCommit.getId());
            repo.writeMergeCommitMsg(message);

            return CherryPickResult.CONFLICT;
         }
      }
      catch (IOException e)
View Full Code Here

   */
  public Set<ObjectId> getAdditionalHaves() {
    HashSet<ObjectId> r = new HashSet<ObjectId>();
    for (AlternateHandle d : objectDatabase. myAlternates()) {
      if (d instanceof AlternateRepository) {
        Repository repo;

        repo = ((AlternateRepository) d).repository;
        for (Ref ref : repo.getAllRefs().values()) {
          if (ref.getObjectId() != null)
            r.add(ref.getObjectId());
          if (ref.getPeeledObjectId() != null)
            r.add(ref.getPeeledObjectId());
        }
        r.addAll(repo.getAdditionalHaves());
      }
    }
    return r;
  }
View Full Code Here

          d = d.getParentFile();
        if (!bare)
          d = new File(d, Constants.DOT_GIT);
        builder.setGitDir(d);
      }
      Repository repository = builder.build();
      if (!repository.getObjectDatabase().exists())
        repository.create(bare);
      return new Git(repository);
    } catch (IOException e) {
      throw new JGitInternalException(e.getMessage(), e);
    }
  }
View Full Code Here

    private Thread worker;

    InternalLocalFetchConnection() throws TransportException {
      super(TransportLocal.this);

      final Repository dst;
      try {
        dst = new FileRepository(remoteGitDir);
      } catch (IOException err) {
        throw new TransportException(uri, JGitText.get().notAGitDirectory);
      }

      final PipedInputStream in_r;
      final PipedOutputStream in_w;

      final PipedInputStream out_r;
      final PipedOutputStream out_w;
      try {
        in_r = new PipedInputStream();
        in_w = new PipedOutputStream(in_r);

        out_r = new PipedInputStream() {
          // The client (BasePackFetchConnection) can write
          // a huge burst before it reads again. We need to
          // force the buffer to be big enough, otherwise it
          // will deadlock both threads.
          {
            buffer = new byte[MIN_CLIENT_BUFFER];
          }
        };
        out_w = new PipedOutputStream(out_r);
      } catch (IOException err) {
        dst.close();
        throw new TransportException(uri, JGitText.get().cannotConnectPipes, err);
      }

      worker = new Thread("JGit-Upload-Pack") {
        public void run() {
          try {
            final UploadPack rp = createUploadPack(dst);
            rp.upload(out_r, in_w, null);
          } catch (IOException err) {
            // Client side of the pipes should report the problem.
            err.printStackTrace();
          } catch (RuntimeException err) {
            // Clients side will notice we went away, and report.
            err.printStackTrace();
          } finally {
            try {
              out_r.close();
            } catch (IOException e2) {
              // Ignore close failure, we probably crashed above.
            }

            try {
              in_w.close();
            } catch (IOException e2) {
              // Ignore close failure, we probably crashed above.
            }

            dst.close();
          }
        }
      };
      worker.start();
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.