private String ourCommitName = null;
+ private MergeStrategy strategy = MergeStrategy.RECURSIVE;
+
/**
* @param repo
*/
String cherryPickName = srcCommit.getId().abbreviate(7).name()
+ " " + srcCommit.getShortMessage(); //$NON-NLS-1$
- ResolveMerger merger = (ResolveMerger) MergeStrategy.RECURSIVE
- .newMerger(repo);
+ ResolveMerger merger = (ResolveMerger) strategy.newMerger(repo);
merger.setWorkingTreeIterator(new FileTreeIterator(repo));
merger.setBase(srcParent.getTree());
merger.setCommitNames(new String[] { "BASE", ourName,
return this;
}
+ /**
+ * @param strategy
+ * The merge strategy to use during this Cherry-pick.
+ * @return {@code this}
+ * @since 3.4
+ */
+ public CherryPickCommand setStrategy(MergeStrategy strategy) {
+ this.strategy = strategy;
+ return this;
+ }
+
private String calculateOurName(Ref headRef) {
if (ourCommitName != null)
return ourCommitName;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryState;
+import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.transport.FetchResult;
/**
private String remoteBranchName;
+ private MergeStrategy strategy = MergeStrategy.RECURSIVE;
+
private enum PullRebaseMode {
USE_CONFIG,
REBASE,
if (doRebase) {
RebaseCommand rebase = new RebaseCommand(repo);
RebaseResult rebaseRes = rebase.setUpstream(commitToMerge)
- .setUpstreamName(upstreamName)
- .setProgressMonitor(monitor).setOperation(Operation.BEGIN)
+ .setUpstreamName(upstreamName).setProgressMonitor(monitor)
+ .setOperation(Operation.BEGIN).setStrategy(strategy)
.call();
result = new PullResult(fetchRes, remote, rebaseRes);
} else {
MergeCommand merge = new MergeCommand(repo);
merge.include(upstreamName, commitToMerge);
+ merge.setStrategy(strategy);
MergeResult mergeRes = merge.call();
monitor.update(1);
result = new PullResult(fetchRes, remote, mergeRes);
public String getRemoteBranchName() {
return remoteBranchName;
}
+
+ /**
+ * @param strategy
+ * The merge strategy to use during this pull operation.
+ * @return {@code this}
+ * @since 3.4
+ */
+ public PullCommand setStrategy(MergeStrategy strategy) {
+ this.strategy = strategy;
+ return this;
+ }
}
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.TreeWalk;
private boolean lastStepWasForward;
+ private MergeStrategy strategy = MergeStrategy.RECURSIVE;
+
/**
* @param repo
*/
String stash = rebaseState.readFile(AUTOSTASH);
try {
Git.wrap(repo).stashApply().setStashRef(stash)
- .ignoreRepositoryState(true).call();
+ .ignoreRepositoryState(true).setStrategy(strategy)
+ .call();
} catch (StashApplyFailureException e) {
conflicts = true;
RevWalk rw = new RevWalk(repo);
String ourCommitName = getOurCommitName();
CherryPickResult cherryPickResult = new Git(repo).cherryPick()
.include(commitToPick).setOurCommitName(ourCommitName)
- .setReflogPrefix("rebase:").call(); //$NON-NLS-1$
+ .setReflogPrefix("rebase:").setStrategy(strategy).call(); //$NON-NLS-1$
switch (cherryPickResult.getStatus()) {
case FAILED:
if (operation == Operation.BEGIN)
return this;
}
+ /**
+ * @param strategy
+ * The merge strategy to use during this rebase operation.
+ * @return {@code this}
+ * @since 3.4
+ */
+ public RebaseCommand setStrategy(MergeStrategy strategy) {
+ this.strategy = strategy;
+ return this;
+ }
+
/**
* Allows configure rebase interactive process and modify commit message
*/
private List<String> unmergedPaths;
+ private MergeStrategy strategy = MergeStrategy.RECURSIVE;
+
/**
* @param repo
*/
String revertName = srcCommit.getId().abbreviate(7).name()
+ " " + srcCommit.getShortMessage(); //$NON-NLS-1$
- ResolveMerger merger = (ResolveMerger) MergeStrategy.RECURSIVE
- .newMerger(repo);
+ ResolveMerger merger = (ResolveMerger) strategy.newMerger(repo);
merger.setWorkingTreeIterator(new FileTreeIterator(repo));
merger.setBase(srcCommit.getTree());
merger.setCommitNames(new String[] {
merger.getBaseCommitId(),
new ObjectId[] { headCommit.getId(),
srcParent.getId() },
- MergeStatus.FAILED, MergeStrategy.RECURSIVE,
+ MergeStatus.FAILED, strategy,
merger.getMergeResults(), failingPaths, null);
else
failingResult = new MergeResult(null,
merger.getBaseCommitId(),
new ObjectId[] { headCommit.getId(),
srcParent.getId() },
- MergeStatus.CONFLICTING,
- MergeStrategy.RECURSIVE,
+ MergeStatus.CONFLICTING, strategy,
merger.getMergeResults(), failingPaths, null);
if (!merger.failed() && !unmergedPaths.isEmpty()) {
String message = new MergeMessageFormatter()
public List<String> getUnmergedPaths() {
return unmergedPaths;
}
+
+ /**
+ * @param strategy
+ * The merge strategy to use during this revert command.
+ * @return {@code this}
+ * @since 3.4
+ */
+ public RevertCommand setStrategy(MergeStrategy strategy) {
+ this.strategy = strategy;
+ return this;
+ }
}
private boolean ignoreRepositoryState;
+ private MergeStrategy strategy = MergeStrategy.RECURSIVE;
+
/**
* Create command to apply the changes of a stashed commit
*
.getParent(1));
ObjectId stashHeadCommit = stashCommit.getParent(0);
- ResolveMerger merger = (ResolveMerger) MergeStrategy.RECURSIVE
- .newMerger(repo);
+ ResolveMerger merger = (ResolveMerger) strategy.newMerger(repo);
merger.setCommitNames(new String[] { "stashed HEAD", "HEAD",
"stash" });
merger.setBase(stashHeadCommit);
dco.setFailOnConflict(true);
dco.checkout(); // Ignoring failed deletes....
if (applyIndex) {
- ResolveMerger ixMerger = (ResolveMerger) MergeStrategy.RECURSIVE
+ ResolveMerger ixMerger = (ResolveMerger) strategy
.newMerger(repo, true);
ixMerger.setCommitNames(new String[] { "stashed HEAD",
"HEAD", "stashed index" });
this.applyIndex = applyIndex;
}
+ /**
+ * @param strategy
+ * The merge strategy to use in order to merge during this
+ * command execution.
+ * @return {@code this}
+ * @since 3.4
+ */
+ public StashApplyCommand setStrategy(MergeStrategy strategy) {
+ this.strategy = strategy;
+ return this;
+ }
+
private void resetIndex(RevTree tree) throws IOException {
DirCache dc = repo.lockDirCache();
TreeWalk walk = null;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.submodule.SubmoduleWalk;
private final Collection<String> paths;
+ private MergeStrategy strategy = MergeStrategy.RECURSIVE;
+
/**
* @param repo
*/
if (ConfigConstants.CONFIG_KEY_MERGE.equals(update)) {
MergeCommand merge = new MergeCommand(submoduleRepo);
merge.include(commit);
+ merge.setStrategy(strategy);
merge.call();
} else if (ConfigConstants.CONFIG_KEY_REBASE.equals(update)) {
RebaseCommand rebase = new RebaseCommand(submoduleRepo);
rebase.setUpstream(commit);
+ rebase.setStrategy(strategy);
rebase.call();
} else {
// Checkout commit referenced in parent repository's
throw new InvalidConfigurationException(e.getMessage(), e);
}
}
+
+ /**
+ * @param strategy
+ * The merge strategy to use during this update operation.
+ * @return {@code this}
+ * @since 3.4
+ */
+ public SubmoduleUpdateCommand setStrategy(MergeStrategy strategy) {
+ this.strategy = strategy;
+ return this;
+ }
}