RebaseResult result = git.rebase().setUpstream("origin/master").runInteractively(handler).call(); System.out.println("Rebase had state: " + result.getStatus() + ": " + result.getConflicts()); result = git.rebase().setUpstream("origin/master").runInteractively(handler).setOperation(RebaseCommand.Operation.ABORT).call(); System.out.println("Aborted reabse with state: " + result.getStatus() + ": " + result.getConflicts());
RebaseResult result = git.rebase().setUpstream("origin/master").runInteractively(handler).call(); System.out.println("Rebase had state: " + result.getStatus() + ": " + result.getConflicts()); result = git.rebase().setUpstream("origin/master").runInteractively(handler).setOperation(RebaseCommand.Operation.ABORT).call(); System.out.println("Aborted reabse with state: " + result.getStatus() + ": " + result.getConflicts());
InteractiveHandler handler = new InteractiveHandler() { public void prepareSteps(List<RebaseTodoLine> steps) { // loop through steps and use setAction to change action } public String modifyCommitMessage(String oldMessage) { return oldMessage; } }; Repository repo = FileRepositoryBuilder.create(gitDir); Git git = Git.wrap(repo); git.rebase().setUpstream(commitA).runInteractively(handler).call();
/** * Abort rebasing if there are any conflicts * @param git * @throws GitAPIException */ private void rebaseAbort(Git git) throws Exception { try { git.rebase() .setOperation(RebaseCommand.Operation.ABORT) .call(); } catch (GitAPIException e) { throw new Exception(GIT_COMMAND_REASON, e); } }
public RebaseResult rebaseFrom(Git git, String branchName) throws GitAPIException { return git.rebase() .setUpstream("origin/" + branchName) // preserving merge commits, otherwise they are removed and it becomes confusing : // we seem to lose some commits during the rebase, even if we don't lose information (since the merge commit is empty) .setPreserveMerges(true) .call(); }
public RebaseResult abortRebase(Git git, String defaultBranch) throws GitAPIException { return git.rebase().setUpstream("origin/" + defaultBranch).setOperation(RebaseCommand.Operation.ABORT).call(); }
@Override public boolean rebase(String upStreamBranchName) { RebaseCommand command = _git.rebase(); RebaseResult result = null; try { command.setUpstream(upStreamBranchName); result = command.call(); // if there are merge conflicts (rebase interactive) - reset the repository if (!result.getStatus().isSuccessful()) { _git.rebase().setOperation(Operation.ABORT).call(); } } catch (Throwable e) { throw new RuntimeException(String.format( "Failed to rebase with upstream [%s]", upStreamBranchName), e); } return result.getStatus().isSuccessful(); }
public boolean rebase() { try { mRepo.getGit().rebase().setUpstream(mUpstream).call(); } catch (StopTaskException e) { return false; } catch (Throwable e) { setException(e); return false; } return true; } }
public boolean rebase() { try { mRepo.getGit().rebase().setUpstream(mUpstream).call(); } catch (StopTaskException e) { return false; } catch (Throwable e) { setException(e); return false; } return true; } }
@Override public void execute() throws GitException, InterruptedException { try (Repository repo = getRepository()) { Git git = git(repo); RebaseResult rebaseResult = git.rebase().setUpstream(upstream).call(); if (!rebaseResult.getStatus().isSuccessful()) { git.rebase().setOperation(Operation.ABORT).call(); throw new GitException("Failed to rebase " + upstream); } } catch (GitAPIException e) { throw new GitException("Failed to rebase " + upstream, e); } } };
git.rebase().runInteractively(squashHandler).setUpstream("HEAD~" + numberOfCommits).call(); } catch (GitAPIException e) { allExceptions.add("Failed to squash last commits", e); try { git.rebase().setOperation(RebaseCommand.Operation.ABORT).call(); } catch (GitAPIException e1) { allExceptions.add("Failed to abort rebase", e1);
@Override public Void call() { try { LOGGER.info("Undo local changes due to failure of git operations"); try { git.rebase().setOperation(RebaseCommand.Operation.ABORT).call(); } catch (WrongRepositoryStateException e) { // ignore rebasing exception when in wrong state } final String remoteBranch = Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + '/' + git.getRepository().getBranch(); git.reset().setMode(ResetType.HARD).setRef(remoteBranch).call(); git.clean().setCleanDirectories(true).call(); try { final ObjectId head = git.getRepository().resolve(Constants.HEAD); LOGGER.info("Undo local changes completed. HEAD is " + head.getName()); } catch (final Exception e) { LOGGER.warn("Failed to fetch HEAD", e); } } catch (final Exception e) { LOGGER.error("Unable to undo changes", e); } return null; } });
@Override public Void call() { try { LOGGER.info("Undo local changes due to failure of git operations"); try { git.rebase().setOperation(RebaseCommand.Operation.ABORT).call(); } catch (WrongRepositoryStateException e) { // ignore rebasing exception when in wrong state } final String remoteBranch = Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + '/' + git.getRepository().getBranch(); git.reset().setMode(ResetType.HARD).setRef(remoteBranch).call(); git.clean().setCleanDirectories(true).call(); try { final ObjectId head = git.getRepository().resolve(Constants.HEAD); LOGGER.info("Undo local changes completed. HEAD is " + head.getName()); } catch (final Exception e) { LOGGER.warn("Failed to fetch HEAD", e); } } catch (final Exception e) { LOGGER.error("Unable to undo changes", e); } return null; } });
git.rebase().runInteractively(renameHandler).setUpstream("HEAD~" + rebaseSize).call(); } catch (GitAPIException e) { try { allExceptions.add("Error during editing commits messages", e); git.rebase().setOperation(RebaseCommand.Operation.ABORT).call(); } catch (GitAPIException e1) { allExceptions.add("Error during aborting rebase", e);
/** * * @return nothing * @throws NotInitializedException * @throws JGitFlowGitAPIException * @throws DirtyWorkingTreeException * @throws JGitFlowIOException * @throws LocalBranchMissingException */ @Override public Void call() throws NotInitializedException, JGitFlowGitAPIException, DirtyWorkingTreeException, JGitFlowIOException, LocalBranchMissingException { requireGitFlowInitialized(); requireCleanWorkingTree(); requireLocalBranchExists(branchName); try { git.checkout().setName(branchName).call(); git.rebase().call(); } catch (GitAPIException e) { throw new JGitFlowGitAPIException(e); } return null; }
assertEquals(pullRes.getRebaseResult().getStatus(), RebaseResult.Status.UP_TO_DATE); RebaseCommand rb = cloned.rebase().setUpstream("origin/master"); RebaseResult rbResult = rb.setPreserveMerges(true).call(); assertTrue(rbResult.getStatus().isSuccessful());
public boolean reset() { try { mRepo.getGit().getRepository().writeMergeCommitMsg(null); mRepo.getGit().getRepository().writeMergeHeads(null); try { mRepo.getGit().rebase().setOperation(RebaseCommand.Operation.ABORT).call(); } catch (Exception e) { } mRepo.getGit().reset().setMode(ResetCommand.ResetType.HARD).call(); } catch (StopTaskException e) { return false; } catch (Throwable e) { setException(e); return false; } return true; } }
public boolean reset() { try { mRepo.getGit().getRepository().writeMergeCommitMsg(null); mRepo.getGit().getRepository().writeMergeHeads(null); try { // if a rebase is in-progress, need to abort it mRepo.getGit().rebase().setOperation(RebaseCommand.Operation.ABORT).call(); } catch (WrongRepositoryStateException e) { // Ignore this, it happens if rebase --abort is called without a rebase in progress. Timber.i(e, "Couldn't abort rebase while reset."); } catch (Exception e) { setException(e, R.string.error_rebase_abort_failed_in_reset); return false; } mRepo.getGit().reset().setMode(ResetCommand.ResetType.HARD).call(); } catch (StopTaskException e) { return false; } catch (Throwable e) { setException(e); return false; } return true; } }
/** * @return nothing * @throws com.atlassian.jgitflow.core.exception.NotInitializedException * @throws com.atlassian.jgitflow.core.exception.JGitFlowGitAPIException * @throws com.atlassian.jgitflow.core.exception.DirtyWorkingTreeException * @throws com.atlassian.jgitflow.core.exception.JGitFlowIOException * @throws com.atlassian.jgitflow.core.exception.LocalBranchMissingException */ @Override public Void call() throws NotInitializedException, JGitFlowGitAPIException, DirtyWorkingTreeException, JGitFlowIOException, LocalBranchMissingException { String prefixedBranchName = gfConfig.getPrefixValue(JGitFlowConstants.PREFIXES.FEATURE.configKey()) + getBranchName(); enforcer().requireGitFlowInitialized(); enforcer().requireCleanWorkingTree(isAllowUntracked()); enforcer().requireLocalBranchExists(prefixedBranchName); try { git.checkout().setName(prefixedBranchName).call(); git.rebase().setUpstream(gfConfig.getDevelop()).call(); } catch (GitAPIException e) { throw new JGitFlowGitAPIException(e); } return null; }
/** * @return nothing * @throws com.atlassian.jgitflow.core.exception.NotInitializedException * @throws com.atlassian.jgitflow.core.exception.JGitFlowGitAPIException * @throws com.atlassian.jgitflow.core.exception.DirtyWorkingTreeException * @throws com.atlassian.jgitflow.core.exception.JGitFlowIOException * @throws com.atlassian.jgitflow.core.exception.LocalBranchMissingException */ @Override public Void call() throws NotInitializedException, JGitFlowGitAPIException, DirtyWorkingTreeException, JGitFlowIOException, LocalBranchMissingException { String prefixedBranchName = gfConfig.getPrefixValue(JGitFlowConstants.PREFIXES.FEATURE.configKey()) + getBranchName(); enforcer().requireGitFlowInitialized(); enforcer().requireCleanWorkingTree(isAllowUntracked()); enforcer().requireLocalBranchExists(prefixedBranchName); try { git.checkout().setName(prefixedBranchName).call(); git.rebase().setUpstream(gfConfig.getDevelop()).call(); } catch (GitAPIException e) { throw new JGitFlowGitAPIException(e); } return null; }