Package org.eclipse.jgit.api.errors

Examples of org.eclipse.jgit.api.errors.JGitInternalException


   *            the file to add
   * @return this instance
   */
  public ResetCommand addPath(String file) {
    if (mode != null)
      throw new JGitInternalException(MessageFormat.format(
          JGitText.get().illegalCombinationOfArguments, "<paths>...",
          "[--mixed | --soft | --hard]"));
    filepaths.add(file);
    return this;
  }
View Full Code Here


        notesCommit = walk.parseCommit(ref.getObjectId());
        map = NoteMap.read(walk.getObjectReader(), notesCommit);
      }
      return map.getNote(id);
    } catch (IOException e) {
      throw new JGitInternalException(e.getMessage(), e);
    } finally {
      walk.release();
    }
  }
View Full Code Here

              JGitText.get().noHEADExistsAndNoExplicitStartingRevisionWasSpecified);
        add(headId);
      } catch (IOException e) {
        // all exceptions thrown by add() shouldn't occur and represent
        // severe low-level exception which are therefore wrapped
        throw new JGitInternalException(
            JGitText.get().anExceptionOccurredWhileTryingToAddTheIdOfHEAD,
            e);
      }
    }
    setCallable(false);
View Full Code Here

    } catch (MissingObjectException e) {
      throw e;
    } catch (IncorrectObjectTypeException e) {
      throw e;
    } catch (IOException e) {
      throw new JGitInternalException(MessageFormat.format(
          JGitText.get().exceptionOccurredDuringAddingOfOptionToALogCommand
          , start), e);
    }
  }
View Full Code Here

      map.set(id, message, inserter);
      commitNoteMap(walk, map, notesCommit, inserter,
          "Notes added by 'git notes add'");
      return map.getNote(id);
    } catch (IOException e) {
      throw new JGitInternalException(e.getMessage(), e);
    } finally {
      inserter.release();
      walk.release();
    }
  }
View Full Code Here

        // specified explicitly
        throw new DetachedHeadException();
      }
      branchName = fullBranch.substring(Constants.R_HEADS.length());
    } catch (IOException e) {
      throw new JGitInternalException(
          JGitText.get().exceptionCaughtDuringExecutionOfPullCommand,
          e);
    }

    if (!repo.getRepositoryState().equals(RepositoryState.SAFE))
      throw new WrongRepositoryStateException(MessageFormat.format(
          JGitText.get().cannotPullOnARepoWithState, repo
              .getRepositoryState().name()));

    // get the configured remote for the currently checked out branch
    // stored in configuration key branch.<branch name>.remote
    Config repoConfig = repo.getConfig();
    String remote = repoConfig.getString(
        ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
        ConfigConstants.CONFIG_KEY_REMOTE);
    if (remote == null)
      // fall back to default remote
      remote = Constants.DEFAULT_REMOTE_NAME;

    // get the name of the branch in the remote repository
    // stored in configuration key branch.<branch name>.merge
    String remoteBranchName = repoConfig.getString(
        ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
        ConfigConstants.CONFIG_KEY_MERGE);
    // check if the branch is configured for pull-rebase
    boolean doRebase = repoConfig.getBoolean(
        ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
        ConfigConstants.CONFIG_KEY_REBASE, false);

    if (remoteBranchName == null) {
      String missingKey = ConfigConstants.CONFIG_BRANCH_SECTION + DOT
          + branchName + DOT + ConfigConstants.CONFIG_KEY_MERGE;
      throw new InvalidConfigurationException(MessageFormat.format(
          JGitText.get().missingConfigurationForKey, missingKey));
    }

    final boolean isRemote = !remote.equals(".");
    String remoteUri;
    FetchResult fetchRes;
    if (isRemote) {
      remoteUri = repoConfig.getString("remote", remote,
          ConfigConstants.CONFIG_KEY_URL);
      if (remoteUri == null) {
        String missingKey = ConfigConstants.CONFIG_REMOTE_SECTION + DOT
            + remote + DOT + ConfigConstants.CONFIG_KEY_URL;
        throw new InvalidConfigurationException(MessageFormat.format(
            JGitText.get().missingConfigurationForKey, missingKey));
      }

      if (monitor.isCancelled())
        throw new CanceledException(MessageFormat.format(
            JGitText.get().operationCanceled,
            JGitText.get().pullTaskName));

      FetchCommand fetch = new FetchCommand(repo);
      fetch.setRemote(remote);
      fetch.setProgressMonitor(monitor);
      fetch.setTimeout(this.timeout);
      fetch.setCredentialsProvider(credentialsProvider);

      fetchRes = fetch.call();
    } else {
      // we can skip the fetch altogether
      remoteUri = "local repository";
      fetchRes = null;
    }

    monitor.update(1);

    if (monitor.isCancelled())
      throw new CanceledException(MessageFormat.format(
          JGitText.get().operationCanceled,
          JGitText.get().pullTaskName));

    // 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(
              JGitText.get().refNotResolved, remoteBranchName));
      } catch (IOException e) {
        throw new JGitInternalException(
            JGitText.get().exceptionCaughtDuringExecutionOfPullCommand,
            e);
      }
    }

    PullResult result;
    if (doRebase) {
      RebaseCommand rebase = new RebaseCommand(repo);
      try {
        RebaseResult rebaseRes = rebase.setUpstream(commitToMerge)
            .setProgressMonitor(monitor).setOperation(
                Operation.BEGIN).call();
        result = new PullResult(fetchRes, remote, rebaseRes);
      } catch (NoHeadException e) {
        throw new JGitInternalException(e.getMessage(), e);
      } catch (RefNotFoundException e) {
        throw new JGitInternalException(e.getMessage(), e);
      } catch (JGitInternalException e) {
        throw new JGitInternalException(e.getMessage(), e);
      } catch (GitAPIException e) {
        throw new JGitInternalException(e.getMessage(), e);
      }
    } else {
      MergeCommand merge = new MergeCommand(repo);
      String name = "branch \'"
          + Repository.shortenRefName(remoteBranchName) + "\' of "
          + remoteUri;
      merge.include(name, commitToMerge);
      MergeResult mergeRes;
      try {
        mergeRes = merge.call();
        monitor.update(1);
        result = new PullResult(fetchRes, remote, mergeRes);
      } catch (NoHeadException e) {
        throw new JGitInternalException(e.getMessage(), e);
      } catch (ConcurrentRefUpdateException e) {
        throw new JGitInternalException(e.getMessage(), e);
      } catch (CheckoutConflictException e) {
        throw new JGitInternalException(e.getMessage(), e);
      } catch (InvalidMergeHeadsException e) {
        throw new JGitInternalException(e.getMessage(), e);
      } catch (WrongRepositoryStateException e) {
        throw new JGitInternalException(e.getMessage(), e);
      } catch (NoMessageException e) {
        throw new JGitInternalException(e.getMessage(), e);
      }
    }
    monitor.endTask();
    return result;
  }
View Full Code Here

      }
    } catch (NoRemoteRepositoryException e) {
      throw new InvalidRemoteException(MessageFormat.format(
          JGitText.get().invalidRemote, remote), e);
    } catch (TransportException e) {
      throw new JGitInternalException(
          JGitText.get().exceptionCaughtDuringExecutionOfFetchCommand,
          e);
    } catch (URISyntaxException e) {
      throw new InvalidRemoteException(MessageFormat.format(
          JGitText.get().invalidRemote, remote));
    } catch (NotSupportedException e) {
      throw new JGitInternalException(
          JGitText.get().exceptionCaughtDuringExecutionOfFetchCommand,
          e);
    }

  }
View Full Code Here

      Iterator<Note> i = map.iterator();
      while (i.hasNext())
        notes.add(i.next());
    } catch (IOException e) {
      throw new JGitInternalException(e.getMessage(), e);
    } finally {
      walk.release();
    }

    return notes;
View Full Code Here

      switch (operation) {
      case ABORT:
        try {
          return abort(RebaseResult.ABORTED_RESULT);
        } catch (IOException ioe) {
          throw new JGitInternalException(ioe.getMessage(), ioe);
        }
      case SKIP:
        // fall through
      case CONTINUE:
        String upstreamCommitName = readFile(rebaseDir, ONTO);
        this.upstreamCommit = walk.parseCommit(repo
            .resolve(upstreamCommitName));
        break;
      case BEGIN:
        RebaseResult res = initFilesAndRewind();
        if (res != null)
          return res;
      }

      if (monitor.isCancelled())
        return abort(RebaseResult.ABORTED_RESULT);

      if (operation == Operation.CONTINUE)
        newHead = continueRebase();

      if (operation == Operation.SKIP)
        newHead = checkoutCurrentHead();

      ObjectReader or = repo.newObjectReader();

      List<Step> steps = loadSteps();
      for (Step step : steps) {
        popSteps(1);
        Collection<ObjectId> ids = or.resolve(step.commit);
        if (ids.size() != 1)
          throw new JGitInternalException(
              "Could not resolve uniquely the abbreviated object ID");
        RevCommit commitToPick = walk
            .parseCommit(ids.iterator().next());
        if (monitor.isCancelled())
          return new RebaseResult(commitToPick);
        try {
          monitor.beginTask(MessageFormat.format(
              JGitText.get().applyingCommit,
              commitToPick.getShortMessage()),
              ProgressMonitor.UNKNOWN);
          // if the first parent of commitToPick is the current HEAD,
          // we do a fast-forward instead of cherry-pick to avoid
          // unnecessary object rewriting
          newHead = tryFastForward(commitToPick);
          lastStepWasForward = newHead != null;
          if (!lastStepWasForward) {
            // TODO if the content of this commit is already merged
            // here we should skip this step in order to avoid
            // confusing pseudo-changed
            CherryPickResult cherryPickResult = new Git(repo)
                .cherryPick().include(commitToPick).call();
            switch (cherryPickResult.getStatus()) {
            case FAILED:
              if (operation == Operation.BEGIN)
                return abort(new RebaseResult(
                    cherryPickResult.getFailingPaths()));
              else
                return stop(commitToPick);
            case CONFLICTING:
              return stop(commitToPick);
            case OK:
              newHead = cherryPickResult.getNewHead();
            }
          }
        } finally {
          monitor.endTask();
        }
      }
      if (newHead != null) {
        String headName = readFile(rebaseDir, HEAD_NAME);
        updateHead(headName, newHead);
        FileUtils.delete(rebaseDir, FileUtils.RECURSIVE);
        if (lastStepWasForward)
          return RebaseResult.FAST_FORWARD_RESULT;
        return RebaseResult.OK_RESULT;
      }
      return RebaseResult.FAST_FORWARD_RESULT;
    } catch (IOException ioe) {
      throw new JGitInternalException(ioe.getMessage(), ioe);
    }
  }
View Full Code Here

      case FAST_FORWARD:
      case FORCED:
      case NO_CHANGE:
        break;
      default:
        throw new JGitInternalException("Updating HEAD failed");
      }
      rup = repo.updateRef(Constants.HEAD);
      res = rup.link(headName);
      switch (res) {
      case FAST_FORWARD:
      case FORCED:
      case NO_CHANGE:
        break;
      default:
        throw new JGitInternalException("Updating HEAD failed");
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.api.errors.JGitInternalException

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.