List of usage examples for org.eclipse.jgit.lib RebaseTodoLine setAction
public void setAction(Action newAction) throws IllegalTodoFileModification
From source file:com.buildautomation.jgit.api.RebaseToOriginMaster.java
License:Apache License
public static void rebaseToOriginMaster() throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // all refs try (Git git = new Git(repository)) { InteractiveHandler handler = new InteractiveHandler() { @Override//from ww w.j av a 2 s.com public void prepareSteps(List<RebaseTodoLine> steps) { for (RebaseTodoLine step : steps) { try { step.setAction(Action.EDIT); } catch (IllegalTodoFileModification e) { throw new IllegalStateException(e); } } } @Override public String modifyCommitMessage(String oldMessage) { return oldMessage; } }; git.rebase().setUpstream("origin/master").runInteractively(handler).call(); System.out.println("Rebased.."); } } }
From source file:edu.nju.cs.inform.jgit.porcelain.RebaseToOriginMaster.java
License:Apache License
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // all refs try (Git git = new Git(repository)) { InteractiveHandler handler = new InteractiveHandler() { @Override//from www .j av a 2s .c om public void prepareSteps(List<RebaseTodoLine> steps) { for (RebaseTodoLine step : steps) { try { step.setAction(Action.EDIT); } catch (IllegalTodoFileModification e) { throw new IllegalStateException(e); } } } @Override public String modifyCommitMessage(String oldMessage) { return oldMessage; } }; git.rebase().setUpstream("origin/master").runInteractively(handler).call(); System.out.println("Rebased.."); } } }
From source file:org.dstadler.jgit.porcelain.RebaseToOriginMaster.java
License:Apache License
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { // all refs try (Git git = new Git(repository)) { InteractiveHandler handler = new InteractiveHandler() { @Override/* w w w. j a v a 2 s. c o m*/ public void prepareSteps(List<RebaseTodoLine> steps) { // the handler receives the list of commits that are rebased, i.e. the ones on the local branch for (RebaseTodoLine step : steps) { // for each step, you can decide which action should be taken // default is PICK try { // by selecting "EDIT", the rebase will stop and ask you to edit the commit-contents step.setAction(Action.EDIT); } catch (IllegalTodoFileModification e) { throw new IllegalStateException(e); } } } @Override public String modifyCommitMessage(String oldMessage) { return oldMessage; } }; RebaseResult result = git.rebase().setUpstream("origin/master").runInteractively(handler).call(); System.out.println("Rebase had state: " + result.getStatus() + ": " + result.getConflicts()); // because of the "EDIT" in the InteractiveHandler, the rebase was stopped in-between // now you can adjust the commit and continue rebasing with setOperation(RebaseCommand.Operation.CONTINUE) // to use the local changes for the commit or setOperation(RebaseCommand.Operation.SKIP) to skip this // commit (i.e. remove it from the branch!) if (!result.getStatus().isSuccessful()) { // if rebasing stopped or failed, you can get back to the original state by running it with setOperation(RebaseCommand.Operation.ABORT) result = git.rebase().setUpstream("origin/master").runInteractively(handler) .setOperation(RebaseCommand.Operation.ABORT).call(); System.out.println( "Aborted reabse with state: " + result.getStatus() + ": " + result.getConflicts()); } } } }
From source file:org.eclipse.egit.core.op.EditCommitOperation.java
License:Open Source License
@Override public void execute(IProgressMonitor m) throws CoreException { IWorkspaceRunnable action = new IWorkspaceRunnable() { @Override/*ww w. j a v a2s . c om*/ public void run(IProgressMonitor pm) throws CoreException { SubMonitor progress = SubMonitor.convert(pm, 2); progress.subTask(MessageFormat.format(CoreText.EditCommitOperation_editing, commit.name())); InteractiveHandler handler = new InteractiveHandler() { @Override public void prepareSteps(List<RebaseTodoLine> steps) { for (RebaseTodoLine step : steps) { if (step.getCommit().prefixCompare(commit) == 0) { try { step.setAction(RebaseTodoLine.Action.EDIT); } catch (IllegalTodoFileModification e) { // shouldn't happen } } } } @Override public String modifyCommitMessage(String oldMessage) { return oldMessage; } }; try (Git git = new Git(repository)) { git.rebase().setUpstream(commit.getParent(0)).runInteractively(handler) .setOperation(RebaseCommand.Operation.BEGIN).call(); } catch (GitAPIException e) { throw new TeamException(e.getLocalizedMessage(), e.getCause()); } progress.worked(1); ProjectUtil.refreshValidProjects(ProjectUtil.getValidOpenProjects(repository), progress.newChild(1)); } }; ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, m); }
From source file:org.eclipse.egit.core.op.RewordCommitOperation.java
License:Open Source License
@Override public void execute(IProgressMonitor m) throws CoreException { IWorkspaceRunnable action = new IWorkspaceRunnable() { @Override//from ww w . ja v a 2 s . c o m public void run(IProgressMonitor pm) throws CoreException { SubMonitor progress = SubMonitor.convert(pm, 2); progress.subTask(MessageFormat.format(CoreText.RewordCommitOperation_rewording, commit.name())); InteractiveHandler handler = new InteractiveHandler() { @Override public void prepareSteps(List<RebaseTodoLine> steps) { for (RebaseTodoLine step : steps) { if (step.getCommit().prefixCompare(commit) == 0) { try { step.setAction(RebaseTodoLine.Action.REWORD); } catch (IllegalTodoFileModification e) { // shouldn't happen } } } } @Override public String modifyCommitMessage(String oldMessage) { return newMessage; } }; try (Git git = new Git(repository)) { git.rebase().setUpstream(commit.getParent(0)).runInteractively(handler) .setOperation(RebaseCommand.Operation.BEGIN).call(); } catch (GitAPIException e) { throw new TeamException(e.getLocalizedMessage(), e.getCause()); } progress.worked(1); ProjectUtil.refreshValidProjects(ProjectUtil.getValidOpenProjects(repository), progress.newChild(1)); } }; ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, m); }
From source file:org.eclipse.egit.core.op.SquashCommitsOperation.java
License:Open Source License
@Override public void execute(IProgressMonitor m) throws CoreException { IWorkspaceRunnable action = new IWorkspaceRunnable() { @Override/*from ww w.jav a2 s . c om*/ public void run(IProgressMonitor pm) throws CoreException { SubMonitor progress = SubMonitor.convert(pm, 2); progress.subTask(MessageFormat.format(CoreText.SquashCommitsOperation_squashing, Integer.valueOf(commits.size()))); InteractiveHandler handler = new InteractiveHandler() { @Override public void prepareSteps(List<RebaseTodoLine> steps) { RevCommit firstCommit = commits.get(0); for (RebaseTodoLine step : steps) { if (isRelevant(step.getCommit())) { try { if (step.getCommit().prefixCompare(firstCommit) == 0) step.setAction(RebaseTodoLine.Action.PICK); else step.setAction(RebaseTodoLine.Action.SQUASH); } catch (IllegalTodoFileModification e) { // shouldn't happen } } } } private boolean isRelevant(AbbreviatedObjectId id) { for (RevCommit commit : commits) { if (id.prefixCompare(commit) == 0) return true; } return false; } @Override public String modifyCommitMessage(String oldMessage) { return messageHandler.modifyCommitMessage(oldMessage); } }; try (Git git = new Git(repository)) { RebaseCommand command = git.rebase().setUpstream(commits.get(0).getParent(0)) .runInteractively(handler).setOperation(RebaseCommand.Operation.BEGIN); MergeStrategy strategy = Activator.getDefault().getPreferredMergeStrategy(); if (strategy != null) { command.setStrategy(strategy); } command.call(); } catch (GitAPIException e) { throw new TeamException(e.getLocalizedMessage(), e.getCause()); } progress.worked(1); ProjectUtil.refreshValidProjects(ProjectUtil.getValidOpenProjects(repository), progress.newChild(1)); } }; ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, m); }