use of org.eclipse.egit.core.op.SquashCommitsOperation 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.egit.core.op.SquashCommitsOperation 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