Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.Ref


    }
  }

  private void validateCommands() {
    for (final ReceiveCommand cmd : commands) {
      final Ref ref = cmd.getRef();
      if (cmd.getResult() != Result.NOT_ATTEMPTED)
        continue;

      if (cmd.getType() == ReceiveCommand.Type.DELETE
          && !isAllowDeletes()) {
        // Deletes are not supported on this repository.
        //
        cmd.setResult(Result.REJECTED_NODELETE);
        continue;
      }

      if (cmd.getType() == ReceiveCommand.Type.CREATE) {
        if (!isAllowCreates()) {
          cmd.setResult(Result.REJECTED_NOCREATE);
          continue;
        }

        if (ref != null && !isAllowNonFastForwards()) {
          // Creation over an existing ref is certainly not going
          // to be a fast-forward update. We can reject it early.
          //
          cmd.setResult(Result.REJECTED_NONFASTFORWARD);
          continue;
        }

        if (ref != null) {
          // A well behaved client shouldn't have sent us a
          // create command for a ref we advertised to it.
          //
          cmd.setResult(Result.REJECTED_OTHER_REASON, MessageFormat
              .format(JGitText.get().refAlreadyExists, ref));
          continue;
        }
      }

      if (cmd.getType() == ReceiveCommand.Type.DELETE && ref != null
          && !ObjectId.zeroId().equals(cmd.getOldId())
          && !ref.getObjectId().equals(cmd.getOldId())) {
        // Delete commands can be sent with the old id matching our
        // advertised value, *OR* with the old id being 0{40}. Any
        // other requested old id is invalid.
        //
        cmd.setResult(Result.REJECTED_OTHER_REASON,
            JGitText.get().invalidOldIdSent);
        continue;
      }

      if (cmd.getType() == ReceiveCommand.Type.UPDATE) {
        if (ref == null) {
          // The ref must have been advertised in order to be updated.
          //
          cmd.setResult(Result.REJECTED_OTHER_REASON, JGitText.get().noSuchRef);
          continue;
        }

        if (!ref.getObjectId().equals(cmd.getOldId())) {
          // A properly functioning client will send the same
          // object id we advertised.
          //
          cmd.setResult(Result.REJECTED_OTHER_REASON,
              JGitText.get().invalidOldIdSent);
View Full Code Here


    // we check the updates to see which of the updated branches
    // corresponds
    // to the remote branch name
    AnyObjectId commitToMerge;
    if (isRemote) {
      Ref r = null;
      if (fetchRes != null) {
        r = fetchRes.getAdvertisedRef(remoteBranchName);
        if (r == null)
          r = fetchRes.getAdvertisedRef(Constants.R_HEADS
              + remoteBranchName);
      }
      if (r == null)
        throw new JGitInternalException(MessageFormat.format(JGitText
            .get().couldNotGetAdvertisedRef, remoteBranchName));
      else
        commitToMerge = r.getObjectId();
    } else {
      try {
        commitToMerge = repo.resolve(remoteBranchName);
        if (commitToMerge == null)
          throw new RefNotFoundException(MessageFormat.format(
View Full Code Here

  private void checkout(Repository clonedRepo, FetchResult result)
      throws JGitInternalException,
      MissingObjectException, IncorrectObjectTypeException, IOException {

    Ref head = result.getAdvertisedRef(branch);
    if (branch.equals(Constants.HEAD)) {
      Ref foundBranch = findBranchToCheckout(result);
      if (foundBranch != null)
        head = foundBranch;
    }

    if (head == null || head.getObjectId() == null)
View Full Code Here

    update.setProgressMonitor(monitor);
    update.call();
  }

  private Ref findBranchToCheckout(FetchResult result) {
    final Ref idHEAD = result.getAdvertisedRef(Constants.HEAD);
    if (idHEAD == null)
      return null;

    Ref master = result.getAdvertisedRef(Constants.R_HEADS
        + Constants.MASTER);
    if (master != null && master.getObjectId().equals(idHEAD.getObjectId()))
      return master;

    Ref foundBranch = null;
    for (final Ref r : result.getAdvertisedRefs()) {
      final String n = r.getName();
      if (!n.startsWith(Constants.R_HEADS))
        continue;
      if (r.getObjectId().equals(idHEAD.getObjectId())) {
View Full Code Here

          // should really not happen
          throw new JGitInternalException(e.getMessage(), e);
        }
      }

      Ref head = repo.getRef(Constants.HEAD);
      if (head == null)
        throw new NoHeadException(
            JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);

      // determine the current HEAD and the commit it is referring to
View Full Code Here

      avail.put(r.getObjectId(), r);

    final Collection<Ref> wants = new ArrayList<Ref>(askFor.values());
    askFor.clear();
    for (final Ref want : wants) {
      final Ref newRef = avail.get(want.getObjectId());
      if (newRef != null) {
        askFor.put(newRef.getObjectId(), newRef);
      } else {
        removeFetchHeadRecord(want.getObjectId());
        removeTrackingRefUpdate(want.getObjectId());
      }
    }
View Full Code Here

    }
  }

  private void expandSingle(final RefSpec spec, final Set<Ref> matched)
      throws TransportException {
    final Ref src = conn.getRef(spec.getSource());
    if (src == null) {
      throw new TransportException(MessageFormat.format(JGitText.get().remoteDoesNotHaveSpec, spec.getSource()));
    }
    if (matched.add(src))
      want(src, spec);
View Full Code Here

    final Map<String, Ref> haveRefs = transport.local.getAllRefs();
    for (final Ref r : conn.getRefs()) {
      if (!isTag(r))
        continue;

      Ref local = haveRefs.get(r.getName());
      ObjectId obj = r.getObjectId();

      if (r.getPeeledObjectId() == null) {
        if (local != null && obj.equals(local.getObjectId()))
          continue;
        if (askFor.containsKey(obj) || transport.local.hasObject(obj))
          wantTag(r);
        else
          additionalTags.add(r);
        continue;
      }

      if (local != null) {
        if (!obj.equals(local.getObjectId()))
          wantTag(r);
      } else if (askFor.containsKey(r.getPeeledObjectId())
          || transport.local.hasObject(r.getPeeledObjectId()))
        wantTag(r);
      else
View Full Code Here

  private void expandFetchTags() throws TransportException {
    final Map<String, Ref> haveRefs = transport.local.getAllRefs();
    for (final Ref r : conn.getRefs()) {
      if (!isTag(r))
        continue;
      final Ref local = haveRefs.get(r.getName());
      if (local == null || !r.getObjectId().equals(local.getObjectId()))
        wantTag(r);
    }
  }
View Full Code Here

      String fullNewName;
      if (repo.getRef(newName) != null)
        throw new RefAlreadyExistsException(MessageFormat.format(
            JGitText.get().refAlreadyExists, newName));
      if (oldName != null) {
        Ref ref = repo.getRef(oldName);
        if (ref == null)
          throw new RefNotFoundException(MessageFormat.format(
              JGitText.get().refNotResolved, oldName));
        if (ref.getName().startsWith(Constants.R_TAGS))
          throw new RefNotFoundException(MessageFormat.format(
              JGitText.get().renameBranchFailedBecauseTag,
              oldName));
        fullOldName = ref.getName();
      } else {
        fullOldName = repo.getFullBranch();
        if (ObjectId.isId(fullOldName))
          throw new DetachedHeadException();
      }

      if (fullOldName.startsWith(Constants.R_REMOTES))
        fullNewName = Constants.R_REMOTES + newName;
      else {
        fullNewName = Constants.R_HEADS + newName;
      }

      if (!Repository.isValidRefName(fullNewName))
        throw new InvalidRefNameException(MessageFormat.format(JGitText
            .get().branchNameInvalid, fullNewName));

      RefRename rename = repo.renameRef(fullOldName, fullNewName);
      Result renameResult = rename.rename();

      setCallable(false);

      boolean ok = Result.RENAMED == renameResult;

      if (ok) {
        if (fullNewName.startsWith(Constants.R_HEADS)) {
          // move the upstream configuration over to the new branch
          String shortOldName = fullOldName
              .substring(Constants.R_HEADS.length());
          final StoredConfig repoConfig = repo.getConfig();
          String oldRemote = repoConfig.getString(
              ConfigConstants.CONFIG_BRANCH_SECTION,
              shortOldName, ConfigConstants.CONFIG_KEY_REMOTE);
          if (oldRemote != null) {
            repoConfig.setString(
                ConfigConstants.CONFIG_BRANCH_SECTION, newName,
                ConfigConstants.CONFIG_KEY_REMOTE, oldRemote);
          }
          String oldMerge = repoConfig.getString(
              ConfigConstants.CONFIG_BRANCH_SECTION,
              shortOldName, ConfigConstants.CONFIG_KEY_MERGE);
          if (oldMerge != null) {
            repoConfig.setString(
                ConfigConstants.CONFIG_BRANCH_SECTION, newName,
                ConfigConstants.CONFIG_KEY_MERGE, oldMerge);
          }
          repoConfig
              .unsetSection(
                  ConfigConstants.CONFIG_BRANCH_SECTION,
                  shortOldName);
          repoConfig.save();
        }

      } else
        throw new JGitInternalException(MessageFormat.format(JGitText
            .get().renameBranchUnexpectedResult, renameResult
            .name()));

      Ref resultRef = repo.getRef(newName);
      if (resultRef == null)
        throw new JGitInternalException(
            JGitText.get().renameBranchFailedUnknownReason);
      return resultRef;
    } catch (IOException ioe) {
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.