use of org.eclipse.jgit.api.RebaseCommand.InteractiveHandler 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);
}
use of org.eclipse.jgit.api.RebaseCommand.InteractiveHandler 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);
}
use of org.eclipse.jgit.api.RebaseCommand.InteractiveHandler in project egit by eclipse.
the class SquashCommitsOperationTest method squash.
@Test
public void squash() throws Exception {
InteractiveHandler messageHandler = new InteractiveHandler() {
@Override
public void prepareSteps(List<RebaseTodoLine> steps) {
// not used
}
@Override
public String modifyCommitMessage(String commit) {
return "squashed";
}
};
List<RevCommit> commits = Arrays.asList(commit1, commit2, commit3);
SquashCommitsOperation op = new SquashCommitsOperation(testRepository.getRepository(), commits, messageHandler);
op.execute(new NullProgressMonitor());
assertEquals(2, countCommitsInHead());
LogCommand log;
try (Git git = new Git(testRepository.getRepository())) {
log = git.log();
}
Iterable<RevCommit> logCommits = log.call();
RevCommit latestCommit = logCommits.iterator().next();
assertEquals("squashed", latestCommit.getFullMessage());
}
use of org.eclipse.jgit.api.RebaseCommand.InteractiveHandler in project egit by eclipse.
the class RebaseCurrentRefCommand method createRebaseOperation.
@Override
protected RebaseOperation createRebaseOperation(Repository repository) throws ExecutionException {
if (LaunchFinder.shouldCancelBecauseOfRunningLaunches(repository, null)) {
return null;
}
InteractiveHandler handler = interactive ? RebaseInteractiveHandler.INSTANCE : null;
RebaseOperation operation = new RebaseOperation(repository, ref, handler);
operation.setPreserveMerges(preserveMerges);
return operation;
}
use of org.eclipse.jgit.api.RebaseCommand.InteractiveHandler in project egit by eclipse.
the class SquashHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
List<RevCommit> commits = getSelectedItems(RevCommit.class, event);
if ((commits == null) || commits.isEmpty())
return null;
Repository repo = getSelectedItem(Repository.class, event);
if (repo == null)
return null;
commits = CommitUtil.sortCommits(commits);
final Shell shell = getPart(event).getSite().getShell();
try {
if (!UIRepositoryUtils.handleUncommittedFiles(repo, shell))
return null;
} catch (GitAPIException e) {
Activator.logError(e.getMessage(), e);
return null;
}
InteractiveHandler messageHandler = new InteractiveHandler() {
@Override
public void prepareSteps(List<RebaseTodoLine> steps) {
// not used
}
@Override
public String modifyCommitMessage(String oldMessage) {
return promptCommitMessage(shell, oldMessage);
}
};
final SquashCommitsOperation op = new SquashCommitsOperation(repo, commits, messageHandler);
Job job = new Job(MessageFormat.format(UIText.SquashHandler_JobName, Integer.valueOf(commits.size()))) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
op.execute(monitor);
} catch (CoreException e) {
Activator.logError(UIText.SquashHandler_InternalError, e);
}
return Status.OK_STATUS;
}
@Override
public boolean belongsTo(Object family) {
if (JobFamilies.SQUASH.equals(family))
return true;
return super.belongsTo(family);
}
};
job.setUser(true);
job.setRule(op.getSchedulingRule());
job.schedule();
return null;
}
Aggregations