/** * Switch to the main branch and delete the temporary branch. * * @throws GitAPIException * @throws RefAlreadyExistsException * @throws RefNotFoundException * @throws InvalidRefNameException * @throws CheckoutConflictException * @throws NotMergedException * @throws CannotDeleteCurrentBranchException */ private void switchToMainAndDeleteFrom(final String tempBranch) throws GitAPIException, RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException, CheckoutConflictException, NotMergedException, CannotDeleteCurrentBranchException { try { repository.reset().setMode(ResetType.HARD).call(); } finally { try { repository.checkout().setCreateBranch(false) .setName(mainBranchName).setForce(true).call(); } finally { try { repository.reset().setMode(ResetType.HARD).call(); } finally { repository.branchDelete().setForce(true) .setBranchNames(tempBranch).call(); } } } }
@Override public Ref call() throws GitAPIException, RefNotFoundException, CheckoutConflictException, InvalidRefNameException, RefAlreadyExistsException { this.checkCallable(); try { this.processOptions(); this.checkoutStartPoint(); RefUpdate update = this.getRepository().updateRef(Constants.HEAD); Result r = update.link(this.getBranchName()); if (EnumSet.of(Result.NEW, Result.FORCED).contains(r) == false) { throw new JGitInternalException(MessageFormat.format( JGitText.get().checkoutUnexpectedResult, r.name())); } this.setCallable(false); return this.getRepository().getRef(Constants.HEAD); } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e); } }
protected void checkout(ObjectId fromId) throws GitAPIException, CheckoutConflictException, IOException { RevWalk rw = new RevWalk(this.getRepository()); try { Ref headRef = this.repo.getRef(Constants.HEAD); AnyObjectId headId = headRef.getObjectId(); RevCommit headCommit = headId == null ? null : rw.parseCommit(headId); RevTree headTree = headCommit == null ? null : headCommit.getTree(); RevCommit from = rw.parseCommit(fromId); this.checkout(headTree, from.getTree()); } finally { rw.release(); } }
protected void checkout(RevTree headTree, RevTree fromTree) throws GitAPIException, CheckoutConflictException, IOException { // DirCacheCheckout free lock of DirCache DirCacheCheckout dco = new DirCacheCheckout(this.getRepository(), headTree, this.repo .lockDirCache(), fromTree); dco.setFailOnConflict(true); try { dco.checkout(); this.toBeDeleted = dco.getToBeDeleted(); } catch (org.eclipse.jgit.errors.CheckoutConflictException e) { this.conflicts = dco.getConflicts(); throw new CheckoutConflictException(dco.getConflicts(), e); } }
private void resetAndRemoveUntrackedFiles( final Git repository ) throws GitAPIException, CheckoutConflictException { repository.clean() // .setCleanDirectories( true ) // .setForce( true ) // .setIgnore( false ) // .call(); // repository.reset() // .setMode( ResetType.HARD ) // .call(); // }
/** * Pull failed because there are uncommitted files that would be in conflict * after the pull. * * @param e Exception. */ protected void showPullFailedBecauseofConflict(CheckoutConflictException e) { new PullWithConflictsDialog( translator.getTranslation(Tags.PULL_STATUS), e.getConflictingPaths(), translator.getTranslation(Tags.PULL_CHECKOUT_CONFLICT_MESSAGE)); }
@Override public void doExecute() { try { MergeCommand mergeCommand = git.merge().setSquash(squash); mergeCommand.include(mergeCommand.getRepository().getRef(branchname)); setupCredentials(mergeCommand); MergeResult mergeResult = null; try { mergeResult = mergeCommand.call(); } catch (CheckoutConflictException conflicts) { throw new BuildException(String.format("%s - Checkout conflicts: %s", MESSAGE_MERGE_FAILED, conflicts.getConflictingPaths())); } if (!mergeResult.getMergeStatus().isSuccessful()) { if (mergeResult.getCheckoutConflicts() != null && mergeResult.getCheckoutConflicts().size() > 0) { throw new BuildException(String.format("%s - Checkout conflicts: %s", MESSAGE_MERGE_FAILED, mergeResult.getCheckoutConflicts())); } if (mergeResult.getFailingPaths() != null && mergeResult.getFailingPaths().size() > 0) { throw new BuildException(String.format("%s - Failing paths: %s", MESSAGE_MERGE_FAILED, mergeResult.getFailingPaths())); } throw new BuildException(String.format(MESSAGE_MERGE_FAILED_WITH_STATUS, mergeResult.getMergeStatus().name())); } } catch (Exception e) { throw new GitBuildException(String.format(MESSAGE_MERGE_FAILED_WITH_URI, getUri()), e); } }
protected void checkoutStartPoint() throws GitAPIException, RefNotFoundException, CheckoutConflictException, IOException { ObjectId sp = this.getStartPoint(); if (sp != null) { this.checkout(sp); } }
@Override public CheckoutResponse checkout(Workspace ws, String name, String startPoint) throws GitAPIException, IOException, GitOperationException { Repository repository = getRepository(ws.getSpaceKey()); try (Git git = Git.wrap(repository)) { CheckoutCommand command = git.checkout().setName(name); if (isRemoteBranch(ws, name)) { throw new GitOperationException("Remote branch must be checkout as new local branch"); } if (StringUtils.isNotEmpty(startPoint)) { command.setStartPoint(startPoint); command.setCreateBranch(true); } try { command.call(); } catch (CheckoutConflictException e) { // Ignore } CheckoutResult result = command.getResult(); CheckoutResult.Status s = result.getStatus(); CheckoutResponse.Status status = CheckoutResponse.Status.OK; if (s == CheckoutResult.Status.CONFLICTS) { status = CheckoutResponse.Status.CONFLICTS; } else if (s == CheckoutResult.Status.ERROR) { status = CheckoutResponse.Status.ERROR; } else if (s == CheckoutResult.Status.NONDELETED) { status = CheckoutResponse.Status.NONDELETED; } else if (s == CheckoutResult.Status.NOT_TRIED) { status = CheckoutResponse.Status.NOT_TRIED; } CheckoutResponse response = new CheckoutResponse(); response.setStatus(status); response.setConflictList(result.getConflictList()); response.setModifiedList(result.getModifiedList()); response.setRemovedList(result.getRemovedList()); response.setUndeletedList(result.getUndeletedList()); publisher.publishEvent(new GitCheckoutEvent(ws, repository.getBranch())); return response; } }
public void applyFilter(Collection<CommitRange> commitRanges, IndexFilter indexFilter) throws IOException, CheckoutConflictException, GitAPIException { applyFilter(commitRanges, indexFilter, NullProgressListener.INSTANCE); }