Package org.eclipse.jgit.api.errors

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


              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

      }
      inserter.flush();
      builder.commit();
      setCallable(false);
    } catch (IOException e) {
      throw new JGitInternalException(
          JGitText.get().exceptionCaughtDuringExecutionOfAddCommand, e);
    } finally {
      inserter.release();
      if (dc != null)
        dc.unlock();
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(
          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);
      }
    }

    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

      FetchResult result = fetch(repository, u);
      if (!noCheckout)
        checkout(repository, result);
      return new Git(repository);
    } catch (IOException ioe) {
      throw new JGitInternalException(ioe.getMessage(), ioe);
    } catch (InvalidRemoteException e) {
      throw new JGitInternalException(e.getMessage(), e);
    } catch (URISyntaxException e) {
      throw new JGitInternalException(e.getMessage(), e);
    }
  }
View Full Code Here

    InitCommand command = Git.init();
    command.setBare(bare);
    if (directory == null)
      directory = new File(u.getHumanishName(), Constants.DOT_GIT);
    if (directory.exists() && directory.listFiles().length != 0)
      throw new JGitInternalException(MessageFormat.format(
          JGitText.get().cloneNonEmptyDirectory, directory.getName()));
    command.setDirectory(directory);
    return command.call().getRepository();
  }
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)
        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());
        } 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) {
      // since UnmergedPathException is a subclass of IOException
      // which should not be wrapped by a JGitInternalException we
      // have to catch and re-throw it here
      throw 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
    dcEditor.commit();
    // finish temporary in-core index used for this commit
    dcBuilder.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);
        }
      }
    }
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

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.