Search in sources :

Example 1 with RebaseTodoLine

use of org.eclipse.jgit.lib.RebaseTodoLine in project egit by eclipse.

the class RebaseInteractivePlan method createElementList.

private List<PlanElement> createElementList(List<RebaseTodoLine> rebaseTodoLines, RevWalk walk) {
    List<PlanElement> planElements = new ArrayList<PlanElement>(rebaseTodoLines.size());
    for (RebaseTodoLine todoLine : rebaseTodoLines) {
        PlanElement element = createElement(todoLine, walk);
        planElements.add(element);
    }
    return planElements;
}
Also used : RebaseTodoLine(org.eclipse.jgit.lib.RebaseTodoLine) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 2 with RebaseTodoLine

use of org.eclipse.jgit.lib.RebaseTodoLine in project egit by eclipse.

the class RewordCommitOperation method execute.

@Override
public void execute(IProgressMonitor m) throws CoreException {
    IWorkspaceRunnable action = new IWorkspaceRunnable() {

        @Override
        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);
}
Also used : RebaseTodoLine(org.eclipse.jgit.lib.RebaseTodoLine) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Git(org.eclipse.jgit.api.Git) IllegalTodoFileModification(org.eclipse.jgit.errors.IllegalTodoFileModification) SubMonitor(org.eclipse.core.runtime.SubMonitor) InteractiveHandler(org.eclipse.jgit.api.RebaseCommand.InteractiveHandler) List(java.util.List)

Example 3 with RebaseTodoLine

use of org.eclipse.jgit.lib.RebaseTodoLine in project egit by eclipse.

the class EditCommitOperation method execute.

@Override
public void execute(IProgressMonitor m) throws CoreException {
    IWorkspaceRunnable action = new IWorkspaceRunnable() {

        @Override
        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);
}
Also used : RebaseTodoLine(org.eclipse.jgit.lib.RebaseTodoLine) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Git(org.eclipse.jgit.api.Git) IllegalTodoFileModification(org.eclipse.jgit.errors.IllegalTodoFileModification) SubMonitor(org.eclipse.core.runtime.SubMonitor) InteractiveHandler(org.eclipse.jgit.api.RebaseCommand.InteractiveHandler) List(java.util.List)

Example 4 with RebaseTodoLine

use of org.eclipse.jgit.lib.RebaseTodoLine in project egit by eclipse.

the class EditCommitOperationTest method edit.

@Test
public void edit() throws Exception {
    EditCommitOperation op = new EditCommitOperation(testRepository.getRepository(), firstCommit);
    op.execute(new NullProgressMonitor());
    assertEquals(RepositoryState.REBASING_INTERACTIVE, testRepository.getRepository().getRepositoryState());
    List<RebaseTodoLine> todos = testRepository.getRepository().readRebaseTodo(GIT_REBASE_TODO, false);
    assertEquals(1, todos.size());
    assertEquals(RebaseTodoLine.Action.PICK, todos.get(0).getAction());
    assertTrue(secondCommit.getId().startsWith(todos.get(0).getCommit()));
    ObjectId headId = testRepository.getRepository().resolve(Constants.HEAD);
    assertEquals(firstCommit.getId(), headId);
}
Also used : RebaseTodoLine(org.eclipse.jgit.lib.RebaseTodoLine) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) EditCommitOperation(org.eclipse.egit.core.op.EditCommitOperation) ObjectId(org.eclipse.jgit.lib.ObjectId) Test(org.junit.Test)

Example 5 with RebaseTodoLine

use of org.eclipse.jgit.lib.RebaseTodoLine in project egit by eclipse.

the class SquashCommitsOperation method execute.

@Override
public void execute(IProgressMonitor m) throws CoreException {
    IWorkspaceRunnable action = new IWorkspaceRunnable() {

        @Override
        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);
}
Also used : RebaseTodoLine(org.eclipse.jgit.lib.RebaseTodoLine) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IllegalTodoFileModification(org.eclipse.jgit.errors.IllegalTodoFileModification) RebaseCommand(org.eclipse.jgit.api.RebaseCommand) MergeStrategy(org.eclipse.jgit.merge.MergeStrategy) SubMonitor(org.eclipse.core.runtime.SubMonitor) InteractiveHandler(org.eclipse.jgit.api.RebaseCommand.InteractiveHandler) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Git(org.eclipse.jgit.api.Git) AbbreviatedObjectId(org.eclipse.jgit.lib.AbbreviatedObjectId) List(java.util.List) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

RebaseTodoLine (org.eclipse.jgit.lib.RebaseTodoLine)5 List (java.util.List)3 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 SubMonitor (org.eclipse.core.runtime.SubMonitor)3 Git (org.eclipse.jgit.api.Git)3 InteractiveHandler (org.eclipse.jgit.api.RebaseCommand.InteractiveHandler)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 IllegalTodoFileModification (org.eclipse.jgit.errors.IllegalTodoFileModification)3 TeamException (org.eclipse.team.core.TeamException)3 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 EditCommitOperation (org.eclipse.egit.core.op.EditCommitOperation)1 RebaseCommand (org.eclipse.jgit.api.RebaseCommand)1 AbbreviatedObjectId (org.eclipse.jgit.lib.AbbreviatedObjectId)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 MergeStrategy (org.eclipse.jgit.merge.MergeStrategy)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 Test (org.junit.Test)1