List of usage examples for org.eclipse.jgit.api.errors RefNotFoundException RefNotFoundException
public RefNotFoundException(String message)
From source file:org.flowerplatform.web.git.operation.internal.PullCommand.java
License:Open Source License
/** * Executes the {@code Pull} command with all the options and parameters * collected by the setter methods (e.g. * {@link #setProgressMonitor(ProgressMonitor)}) of this class. Each * instance of this class should only be used for one invocation of the * command. Don't call this method twice on an instance. * * @return the result of the pull/*from w w w. j av a2 s. c om*/ * @throws WrongRepositoryStateException * @throws InvalidConfigurationException * @throws DetachedHeadException * @throws InvalidRemoteException * @throws CanceledException * @throws RefNotFoundException * @throws NoHeadException * @throws org.eclipse.jgit.api.errors.TransportException * @throws GitAPIException */ @SuppressWarnings("restriction") public PullResult call() throws GitAPIException, WrongRepositoryStateException, InvalidConfigurationException, DetachedHeadException, InvalidRemoteException, CanceledException, RefNotFoundException, NoHeadException, org.eclipse.jgit.api.errors.TransportException { checkCallable(); monitor.beginTask(JGitText.get().pullTaskName, 2); Object[] data = GitPlugin.getInstance().getUtils().getFetchPushUpstreamDataRefSpecAndRemote(repo); String fullBranch = (String) data[0]; String branchName = fullBranch.substring(Constants.R_HEADS.length()); 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 = (String) data[1]; // determines whether rebase should be used after fetching boolean doRebase = (boolean) data[3]; final boolean isRemote = !remote.equals("."); //$NON-NLS-1$ String remoteUri; FetchResult fetchRes; if (isRemote) { remoteUri = (String) data[2]; if (monitor.isCancelled()) throw new CanceledException( MessageFormat.format(JGitText.get().operationCanceled, JGitText.get().pullTaskName)); RefSpec refSpec = new RefSpec(); refSpec = refSpec.setForceUpdate(true); refSpec = refSpec.setSourceDestination(remoteBranchName, fullBranch); FetchCommand fetch = new Git(repo).fetch().setRemote(remote).setRefSpecs(refSpec); 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); } } String upstreamName = "branch \'" + Repository.shortenRefName(remoteBranchName) + "\' of " + remoteUri; PullResult result; if (doRebase) { RebaseCommand rebase = new Git(repo).rebase(); RebaseResult rebaseRes = rebase.setUpstream(commitToMerge).setUpstreamName(upstreamName) .setProgressMonitor(monitor).setOperation(Operation.BEGIN).call(); result = new PullResult(fetchRes, remote, rebaseRes); } else { MergeCommand merge = new Git(repo).merge(); merge.include(upstreamName, commitToMerge); MergeResult mergeRes = merge.call(); monitor.update(1); result = new PullResult(fetchRes, remote, mergeRes); } monitor.endTask(); return result; }
From source file:util.ChkoutCmd.java
License:Eclipse Distribution License
/** * @throws RefAlreadyExistsException// w ww .ja v a2s . c o m * when trying to create (without force) a branch with a name * that already exists * @throws RefNotFoundException * if the start point or branch can not be found * @throws InvalidRefNameException * if the provided name is <code>null</code> or otherwise * invalid * @throws CheckoutConflictException * if the checkout results in a conflict * @return the newly created branch */ public Ref call() throws GitAPIException, RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException, CheckoutConflictException { checkCallable(); processOptions(); try { if (checkoutAllPaths || !paths.isEmpty()) { checkoutPaths(); status = new CheckoutResult(Status.OK, paths); setCallable(false); return null; } if (createBranch) { Git git = new Git(repo); CreateBranchCommand command = git.branchCreate(); command.setName(name); command.setStartPoint(getStartPoint().name()); if (upstreamMode != null) command.setUpstreamMode(upstreamMode); command.call(); } Ref headRef = repo.getRef(Constants.HEAD); String shortHeadRef = getShortBranchName(headRef); String refLogMessage = "checkout: moving from " + shortHeadRef; //$NON-NLS-1$ 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; DirCache dc = repo.lockDirCache(); try { dco = new DirCacheCheckout(repo, headTree, dc, newCommit.getTree()); dco.setFailOnConflict(false); try { dco.checkout(); } catch (org.eclipse.jgit.errors.CheckoutConflictException e) { status = new CheckoutResult(Status.CONFLICTS, dco.getConflicts()); throw new CheckoutConflictException(dco.getConflicts(), e); } } finally { dc.unlock(); } 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); //$NON-NLS-1$ Result updateResult; if (ref != null) updateResult = refUpdate.link(ref.getName()); else { refUpdate.setNewObjectId(newCommit); updateResult = refUpdate.forceUpdate(); } setCallable(false); boolean ok = false; switch (updateResult) { case NEW: ok = true; break; case NO_CHANGE: case FAST_FORWARD: case FORCED: ok = true; break; default: break; } if (!ok) throw new JGitInternalException( MessageFormat.format(JGitText.get().checkoutUnexpectedResult, updateResult.name())); if (!dco.getToBeDeleted().isEmpty()) { status = new CheckoutResult(Status.NONDELETED, dco.getToBeDeleted()); } else status = new CheckoutResult(new ArrayList<String>(dco.getUpdated().keySet()), dco.getRemoved()); return ref; } catch (IOException ioe) { throw new JGitInternalException(ioe.getMessage(), ioe); } finally { if (status == null) status = CheckoutResult.ERROR_RESULT; } }
From source file:util.ChkoutCmd.java
License:Eclipse Distribution License
private ObjectId getStartPoint() throws AmbiguousObjectException, RefNotFoundException, IOException { if (startCommit != null) return startCommit.getId(); ObjectId result = null;/*www .j a v a 2 s .com*/ try { result = repo.resolve((startPoint == null) ? Constants.HEAD : startPoint); } catch (AmbiguousObjectException e) { throw e; } if (result == null) throw new RefNotFoundException(MessageFormat.format(JGitText.get().refNotResolved, startPoint != null ? startPoint : Constants.HEAD)); return result; }