Package org.eclipse.jgit.api.errors

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


            return CherryPickResult.CONFLICT;
         }
      }
      catch (IOException e)
      {
         throw new JGitInternalException(
                  MessageFormat.format(
                           JGitText.get().exceptionCaughtDuringExecutionOfCherryPickCommand,
                           e), e);
      }
      finally
View Full Code Here


            throw new RefAlreadyExistsException(
                MessageFormat.format(
                    JGitText.get().tagAlreadyExists,
                    newTag.toString()));
          default:
            throw new JGitInternalException(MessageFormat.format(
                JGitText.get().updatingRefFailed, refName,
                newTag.toString(), updateResult));
          }

        } finally {
          revWalk.release();
        }

      } finally {
        inserter.release();
      }

    } catch (IOException e) {
      throw new JGitInternalException(
          JGitText.get().exceptionCaughtDuringExecutionOfTagCommand,
          e);
    }
  }
View Full Code Here

          git.add()
              .addFilepattern(".")
              .setUpdate(true).call();
        } catch (NoFilepatternException e) {
          // 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
      ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}");
      if (headId == null && amend)
        throw new WrongRepositoryStateException(
            JGitText.get().commitAmendOnInitialNotPossible);

      if (headId != null)
        if (amend) {
          RevCommit previousCommit = new RevWalk(repo)
              .parseCommit(headId);
          RevCommit[] p = previousCommit.getParents();
          for (int i = 0; i < p.length; i++)
            parents.add(0, p[i].getId());
          if (author == null)
            author = previousCommit.getAuthorIdent();
        } else {
          parents.add(0, headId);
        }

      // lock the index
      DirCache index = repo.lockDirCache();
      try {
        if (!only.isEmpty())
          index = createTemporaryIndex(headId, index);

        ObjectInserter odi = repo.newObjectInserter();
        try {
          // Write the index as tree to the object database. This may
          // fail for example when the index contains unmerged paths
          // (unresolved conflicts)
          ObjectId indexTreeId = index.writeTree(odi);

          if (insertChangeId)
            insertChangeId(indexTreeId);

          // Create a Commit object, populate it and write it
          CommitBuilder commit = new CommitBuilder();
          commit.setCommitter(committer);
          commit.setAuthor(author);
          commit.setMessage(message);

          commit.setParentIds(parents);
          commit.setTreeId(indexTreeId);
          ObjectId commitId = odi.insert(commit);
          odi.flush();

          RevWalk revWalk = new RevWalk(repo);
          try {
            RevCommit revCommit = revWalk.parseCommit(commitId);
            RefUpdate ru = repo.updateRef(Constants.HEAD);
            ru.setNewObjectId(commitId);
            if (reflogComment != null) {
              ru.setRefLogMessage(reflogComment, false);
            } else {
              String prefix = amend ? "commit (amend): "
                  : "commit: ";
              ru.setRefLogMessage(
                  prefix + revCommit.getShortMessage(), false);
            }
            if (headId != null)
              ru.setExpectedOldObjectId(headId);
            else
              ru.setExpectedOldObjectId(ObjectId.zeroId());
            Result rc = ru.forceUpdate();
            switch (rc) {
            case NEW:
            case FORCED:
            case FAST_FORWARD: {
              setCallable(false);
              if (state == RepositoryState.MERGING_RESOLVED) {
                // Commit was successful. Now delete the files
                // used for merge commits
                repo.writeMergeCommitMsg(null);
                repo.writeMergeHeads(null);
              } else if (state == RepositoryState.CHERRY_PICKING_RESOLVED) {
                repo.writeMergeCommitMsg(null);
                repo.writeCherryPickHead(null);
              }
              return revCommit;
            }
            case REJECTED:
            case LOCK_FAILURE:
              throw new ConcurrentRefUpdateException(JGitText
                  .get().couldNotLockHEAD, ru.getRef(), rc);
            default:
              throw new JGitInternalException(MessageFormat
                  .format(JGitText.get().updatingRefFailed,
                      Constants.HEAD,
                      commitId.toString(), rc));
            }
          } finally {
            revWalk.release();
          }
        } finally {
          odi.release();
        }
      } finally {
        index.unlock();
      }
    } catch (UnmergedPathException e) {
      throw new UnmergedPathsException(e);
    } catch (IOException e) {
      throw new JGitInternalException(
          JGitText.get().exceptionCaughtDuringExecutionOfCommitCommand, e);
    }
  }
View Full Code Here

    // there must be no unprocessed paths left at this point; otherwise an
    // untracked or unknown path has been specified
    for (int i = 0; i < onlyProcessed.length; i++)
      if (!onlyProcessed[i])
        throw new JGitInternalException(MessageFormat.format(
            JGitText.get().entryNotFoundByPath, only.get(i)));

    // there must be at least one change
    if (emptyCommit)
      throw new JGitInternalException(JGitText.get().emptyCommit);

    // update index
    existingBuilder.commit();
    // finish temporary in-core index used for this commit
    tempBuilder.finish();
View Full Code Here

    // when doing a merge commit parse MERGE_HEAD and MERGE_MSG files
    if (state == RepositoryState.MERGING_RESOLVED) {
      try {
        parents = repo.readMergeHeads();
      } catch (IOException e) {
        throw new JGitInternalException(MessageFormat.format(
            JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR,
            Constants.MERGE_HEAD, e), e);
      }
      if (message == null) {
        try {
          message = repo.readMergeCommitMsg();
        } catch (IOException e) {
          throw new JGitInternalException(MessageFormat.format(
              JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR,
              Constants.MERGE_MSG, e), e);
        }
      }
    } else if (state == RepositoryState.SAFE && message == null) {
      try {
        message = repo.readSquashCommitMsg();
        if (message != null)
          repo.writeSquashCommitMsg(null /* delete */);
      } catch (IOException e) {
        throw new JGitInternalException(MessageFormat.format(
            JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR,
            Constants.MERGE_MSG, e), e);
      }

    }
View Full Code Here

   *             in case of an illegal combination of arguments/ options
   */
  public CommitCommand setAll(boolean all) {
    checkCallable();
    if (!only.isEmpty())
      throw new JGitInternalException(MessageFormat.format(
          JGitText.get().illegalCombinationOfArguments, "--all",
          "--only"));
    this.all = all;
    return this;
  }
View Full Code Here

   * @return {@code this}
   */
  public CommitCommand setOnly(String only) {
    checkCallable();
    if (all)
      throw new JGitInternalException(MessageFormat.format(
          JGitText.get().illegalCombinationOfArguments, "--only",
          "--all"));
    String o = only.endsWith("/") ? only.substring(0, only.length() - 1)
        : only;
    // ignore duplicates
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);

        // determines whether rebase should be used after fetching
        boolean doRebase = false;
        switch (pullRebaseMode) {
            case REBASE:
                doRebase = true;
                break;
            case NO_REBASE:
                doRebase = false;
                break;
            case USE_CONFIG:
            default:
                // check if the branch is configured for pull-rebase
                doRebase = repoConfig.getBoolean(
                        ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
                        ConfigConstants.CONFIG_KEY_REBASE, false);
                break;
        }

    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(
          ConfigConstants.CONFIG_REMOTE_SECTION, 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);
      configure(fetch);

      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);
      }
    }
View Full Code Here

              FileUtils.delete(new File(repo.getWorkTree(), dir),
                  FileUtils.RECURSIVE);
            files.add(dir + "/");
          }
    } catch (IOException e) {
      throw new JGitInternalException(e.getMessage(), e);
    }
    return files;
  }
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 upstreamCommitId = readFile(rebaseDir, ONTO);
        try {
          upstreamCommitName = readFile(rebaseDir, ONTO_NAME);
        } catch (FileNotFoundException e) {
          // Fall back to commit ID if file doesn't exist (e.g. rebase
          // was started by C Git)
          upstreamCommitName = upstreamCommitId;
        }
        this.upstreamCommit = walk.parseCommit(repo
            .resolve(upstreamCommitId));
        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();

        File amendFile = new File(rebaseDir, AMEND);
        boolean amendExists = amendFile.exists();
        if (amendExists) {
          FileUtils.delete(amendFile);
        }
        if (newHead == null && !amendExists) {
          // continueRebase() returns null only if no commit was
          // neccessary. This means that no changes where left over
          // after resolving all conflicts. In this case, cgit stops
          // and displays a nice message to the user, telling him to
          // either do changes or skip the commit instead of continue.
          return RebaseResult.NOTHING_TO_COMMIT_RESULT;
        }
      }

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

      ObjectReader or = repo.newObjectReader();

      List<Step> steps = loadSteps();
      if (isInteractive()) {
        interactiveHandler.prepareSteps(steps);
        BufferedWriter fw = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(new File(
                rebaseDir, GIT_REBASE_TODO)),
                Constants.CHARACTER_ENCODING));
        fw.newLine();
        try {
          StringBuilder sb = new StringBuilder();
          for (Step step : steps) {
            sb.setLength(0);
            sb.append(step.action.token);
            sb.append(" ");
            sb.append(step.commit.name());
            sb.append(" ");
            sb.append(RawParseUtils.decode(step.shortMessage)
                .trim());
            fw.write(sb.toString());
            fw.newLine();
          }
        } finally {
          fw.close();
        }
      }
      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
            String ourCommitName = getOurCommitName();
            CherryPickResult cherryPickResult = new Git(repo)
                .cherryPick().include(commitToPick)
                .setOurCommitName(ourCommitName).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();
            }
          }
          switch (step.action) {
          case PICK:
            continue; // continue rebase process on pick command
          case REWORD:
            String oldMessage = commitToPick.getFullMessage();
            String newMessage = interactiveHandler
                .modifyCommitMessage(oldMessage);
            newHead = new Git(repo).commit().setMessage(newMessage)
                .setAmend(true).call();
            continue;
          case EDIT:
            createFile(rebaseDir, AMEND, commitToPick.name());
            return stop(commitToPick);
          }
        } 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

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.