use of org.eclipse.jgit.merge.MergeStrategy in project egit by eclipse.
the class CherryPickOperation 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.CherryPickOperation_cherryPicking, commit.name()));
try (Git git = new Git(repo)) {
CherryPickCommand command = git.cherryPick().include(commit.getId());
MergeStrategy strategy = Activator.getDefault().getPreferredMergeStrategy();
if (strategy != null) {
command.setStrategy(strategy);
}
result = command.call();
} catch (GitAPIException e) {
throw new TeamException(e.getLocalizedMessage(), e.getCause());
}
progress.worked(1);
ProjectUtil.refreshValidProjects(ProjectUtil.getValidOpenProjects(repo), progress.newChild(1));
}
};
ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, m);
}
use of org.eclipse.jgit.merge.MergeStrategy in project egit by eclipse.
the class SubmoduleUpdateOperation method execute.
@Override
public void execute(final IProgressMonitor monitor) throws CoreException {
IWorkspaceRunnable action = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor pm) throws CoreException {
RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
SubMonitor progress = SubMonitor.convert(pm, 4);
progress.setTaskName(MessageFormat.format(CoreText.SubmoduleUpdateOperation_updating, util.getRepositoryName(repository)));
Git git = Git.wrap(repository);
Collection<String> updated = null;
try {
SubmoduleInitCommand init = git.submoduleInit();
for (String path : paths) init.addPath(path);
init.call();
progress.worked(1);
SubmoduleUpdateCommand update = git.submoduleUpdate();
for (String path : paths) update.addPath(path);
update.setProgressMonitor(new EclipseGitProgressTransformer(progress.newChild(2)));
MergeStrategy strategy = Activator.getDefault().getPreferredMergeStrategy();
if (strategy != null) {
update.setStrategy(strategy);
}
update.setCallback(new CloneCommand.Callback() {
@Override
public void initializedSubmodules(Collection<String> submodules) {
// Nothing to do
}
@Override
public void cloningSubmodule(String path) {
progress.setTaskName(MessageFormat.format(CoreText.SubmoduleUpdateOperation_cloning, util.getRepositoryName(repository), path));
}
@Override
public void checkingOut(AnyObjectId commit, String path) {
// Nothing to do
}
});
updated = update.call();
SubMonitor refreshMonitor = progress.newChild(1).setWorkRemaining(updated.size());
for (String path : updated) {
Repository subRepo = SubmoduleWalk.getSubmoduleRepository(repository, path);
if (subRepo != null) {
ProjectUtil.refreshValidProjects(ProjectUtil.getValidOpenProjects(subRepo), refreshMonitor.newChild(1));
} else {
refreshMonitor.worked(1);
}
}
} catch (GitAPIException e) {
throw new TeamException(e.getLocalizedMessage(), e.getCause());
} catch (IOException e) {
throw new TeamException(e.getLocalizedMessage(), e.getCause());
} finally {
if (updated != null && !updated.isEmpty()) {
repository.notifyIndexChanged();
}
}
}
};
ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor);
}
use of org.eclipse.jgit.merge.MergeStrategy in project egit by eclipse.
the class RebaseOperation method execute.
@Override
public void execute(IProgressMonitor m) throws CoreException {
if (result != null)
throw new CoreException(new Status(IStatus.ERROR, Activator.getPluginId(), CoreText.OperationAlreadyExecuted));
final IProject[] validProjects = ProjectUtil.getValidOpenProjects(repository);
IWorkspaceRunnable action = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor actMonitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(actMonitor, 2);
try (Git git = new Git(repository)) {
RebaseCommand cmd = git.rebase().setProgressMonitor(new EclipseGitProgressTransformer(progress.newChild(1)));
MergeStrategy strategy = Activator.getDefault().getPreferredMergeStrategy();
if (strategy != null) {
cmd.setStrategy(strategy);
}
if (handler != null) {
cmd.runInteractively(handler, true);
}
if (operation == Operation.BEGIN) {
cmd.setPreserveMerges(preserveMerges);
result = cmd.setUpstream(ref.getName()).call();
} else {
result = cmd.setOperation(operation).call();
}
} catch (JGitInternalException | GitAPIException e) {
throw new CoreException(Activator.error(e.getMessage(), e));
} finally {
if (refreshNeeded()) {
ProjectUtil.refreshValidProjects(validProjects, progress.newChild(1));
}
}
}
};
ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, m);
}
use of org.eclipse.jgit.merge.MergeStrategy 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);
}
use of org.eclipse.jgit.merge.MergeStrategy in project egit by eclipse.
the class StashApplyOperation method execute.
@Override
public void execute(IProgressMonitor monitor) throws CoreException {
IWorkspaceRunnable action = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor pm) throws CoreException {
SubMonitor progress = SubMonitor.convert(pm, 3);
try {
IProject[] validProjects = ProjectUtil.getValidOpenProjects(repository);
progress.worked(1);
StashApplyCommand command = Git.wrap(repository).stashApply().setStashRef(commit.name());
MergeStrategy strategy = Activator.getDefault().getPreferredMergeStrategy();
if (strategy != null) {
command.setStrategy(strategy);
}
command.call();
progress.worked(1);
ProjectUtil.refreshValidProjects(validProjects, progress.newChild(1));
} catch (JGitInternalException e) {
throw new TeamException(e.getLocalizedMessage(), e.getCause());
} catch (GitAPIException e) {
throw new TeamException(e.getLocalizedMessage(), e.getCause());
}
}
};
ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor);
}
Aggregations