Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.Ref


    if (!url.startsWith("./") && !url.startsWith("../"))
      return url;

    String remoteName = null;
    // Look up remote URL associated wit HEAD ref
    Ref ref = parent.getRef(Constants.HEAD);
    if (ref != null) {
      if (ref.isSymbolic())
        ref = ref.getLeaf();
      remoteName = parent.getConfig().getString(
          ConfigConstants.CONFIG_BRANCH_SECTION,
          Repository.shortenRefName(ref.getName()),
          ConfigConstants.CONFIG_KEY_REMOTE);
    }

    // Fall back to 'origin' if current HEAD ref has no remote URL
    if (remoteName == null)
View Full Code Here


   */
  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

   * @param subRepo
   * @return shortened branch name, null on failures
   * @throws IOException
   */
  protected String getHeadBranch(final Repository subRepo) throws IOException {
    Ref head = subRepo.getRef(Constants.HEAD);
    if (head != null && head.isSymbolic())
      return Repository.shortenRefName(head.getLeaf().getName());
    else
      return null;
  }
View Full Code Here

        RemoteConfig config = new RemoteConfig(repo.getConfig(),
            getRemote());
        refSpecs.addAll(config.getPushRefSpecs());
      }
      if (refSpecs.isEmpty()) {
        Ref head = repo.getRef(Constants.HEAD);
        if (head != null && head.isSymbolic())
          refSpecs.add(new RefSpec(head.getLeaf().getName()));
      }

      if (force) {
        for (int i = 0; i < refSpecs.size(); i++)
          refSpecs.set(i, refSpecs.get(i).setForceUpdate(true));
View Full Code Here

   */
  public PushCommand add(String nameOrSpec) throws JGitInternalException {
    if (0 <= nameOrSpec.indexOf(':')) {
      refSpecs.add(new RefSpec(nameOrSpec));
    } else {
      Ref src;
      try {
        src = repo.getRef(nameOrSpec);
      } catch (IOException e) {
        throw new JGitInternalException(
            JGitText.get().exceptionCaughtDuringExecutionOfPushCommand,
View Full Code Here

    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;

      // loop through all refs to be cherry-picked
      for (Ref src : commits) {
View Full Code Here

        if (upstreamMode != null)
          command.setUpstreamMode(upstreamMode);
        command.call();
      }

      Ref headRef = repo.getRef(Constants.HEAD);
      String shortHeadRef = getShortBranchName(headRef);
      String refLogMessage = "checkout: moving from " + shortHeadRef;
      ObjectId branch = repo.resolve(name);
      if (branch == null)
        throw new RefNotFoundException(MessageFormat.format(JGitText
            .get().refNotResolved, name));

      RevWalk revWalk = new RevWalk(repo);
      AnyObjectId headId = headRef.getObjectId();
      RevCommit headCommit = headId == null ? null : revWalk
          .parseCommit(headId);
      RevCommit newCommit = revWalk.parseCommit(branch);
      RevTree headTree = headCommit == null ? null : headCommit.getTree();
      DirCacheCheckout dco = new DirCacheCheckout(repo, headTree,
          repo.lockDirCache(), newCommit.getTree());
      dco.setFailOnConflict(true);
      try {
        dco.checkout();
      } catch (CheckoutConflictException e) {
        status = new CheckoutResult(Status.CONFLICTS, dco
            .getConflicts());
        throw e;
      }
      Ref ref = repo.getRef(name);
      if (ref != null && !ref.getName().startsWith(Constants.R_HEADS))
        ref = null;
      String toName = Repository.shortenRefName(name);
      RefUpdate refUpdate = repo.updateRef(Constants.HEAD, ref == null);
      refUpdate.setForceUpdate(force);
      refUpdate.setRefLogMessage(refLogMessage + " to " + toName, false);
      Result updateResult;
      if (ref != null)
        updateResult = refUpdate.link(ref.getName());
      else {
        refUpdate.setNewObjectId(newCommit);
        updateResult = refUpdate.forceUpdate();
      }
View Full Code Here

    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;

      // loop through all refs to be reverted
      for (Ref src : commits) {
View Full Code Here

  private RebaseResult initFilesAndRewind() throws RefNotFoundException,
      IOException, NoHeadException, JGitInternalException {
    // we need to store everything into files so that we can implement
    // --skip, --continue, and --abort

    Ref head = repo.getRef(Constants.HEAD);
    if (head == null || head.getObjectId() == null)
      throw new RefNotFoundException(MessageFormat.format(
          JGitText.get().refNotResolved, Constants.HEAD));

    String headName;
    if (head.isSymbolic())
      headName = head.getTarget().getName();
    else
      headName = "detached HEAD";
    ObjectId headId = head.getObjectId();
    if (headId == null)
      throw new RefNotFoundException(MessageFormat.format(
          JGitText.get().refNotResolved, Constants.HEAD));
    RevCommit headCommit = walk.lookupCommit(headId);
    RevCommit upstream = walk.lookupCommit(upstreamCommit.getId());
View Full Code Here

   * @throws RefNotFoundException
   * @throws IOException
   */
  public RevCommit tryFastForward(RevCommit newCommit)
      throws RefNotFoundException, IOException {
    Ref head = repo.getRef(Constants.HEAD);
    if (head == null || head.getObjectId() == null)
      throw new RefNotFoundException(MessageFormat.format(
          JGitText.get().refNotResolved, Constants.HEAD));

    ObjectId headId = head.getObjectId();
    if (headId == null)
      throw new RefNotFoundException(MessageFormat.format(
          JGitText.get().refNotResolved, Constants.HEAD));
    RevCommit headCommit = walk.lookupCommit(headId);
    if (walk.isMergedInto(newCommit, headCommit))
      return newCommit;

    String headName;
    if (head.isSymbolic())
      headName = head.getTarget().getName();
    else
      headName = "detached HEAD";
    return tryFastForward(headName, headCommit, newCommit);
  }
View Full Code Here

TOP

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

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.