aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2021-04-12 23:50:54 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2021-04-19 01:52:19 +0200
commit8210f29fe43ccd35e7d2ed3ed45a84a75b2717c4 (patch)
treee226ef95a4bd159017444cda259d7437374c3759 /org.eclipse.jgit.pgm
parent983c25064edeada19bd46aa604a9b90e23778a90 (diff)
downloadjgit-8210f29fe43ccd35e7d2ed3ed45a84a75b2717c4.tar.gz
jgit-8210f29fe43ccd35e7d2ed3ed45a84a75b2717c4.zip
Implement ours/theirs content conflict resolution
Git has different conflict resolution strategies: * There is a tree merge strategy "ours" which just ignores any changes from theirs ("-s ours"). JGit also has the mirror strategy "theirs" ignoring any changes from "ours". (This doesn't exist in C git.) Adapt StashApplyCommand and CherrypickCommand to be able to use those tree merge strategies. * For the resolve/recursive tree merge strategies, there are content conflict resolution strategies "ours" and "theirs", which resolve any conflict hunks by taking the "ours" or "theirs" hunk. In C git those correspond to "-Xours" or -Xtheirs". Implement that in MergeAlgorithm, and add API to set and pass through such a strategy for resolving content conflicts. * The "ours/theirs" content conflict resolution strategies also apply for binary files. Handle these cases in ResolveMerger. Note that the content conflict resolution strategies ("-X ours/theirs") do _not_ apply to modify/delete or delete/modify conflicts. Such conflicts are always reported as conflicts by C git. They do apply, however, if one side completely clears a file's content. Bug: 501111 Change-Id: I2c9c170c61c440a2ab9c387991e7a0c3ab960e07 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.pgm')
-rw-r--r--org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties3
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java22
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java1
3 files changed, 24 insertions, 2 deletions
diff --git a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties
index 83846ee8e9..38deab99a0 100644
--- a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties
+++ b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties
@@ -115,6 +115,7 @@ metaVar_configFile=FILE
metaVar_connProp=conn.prop
metaVar_diffAlg=ALGORITHM
metaVar_directory=DIRECTORY
+metaVar_extraArgument=ours|theirs
metaVar_file=FILE
metaVar_filepattern=filepattern
metaVar_gitDir=GIT_DIR
@@ -217,6 +218,7 @@ timeInMilliSeconds={0} ms
treeIsRequired=argument tree is required
tooManyRefsGiven=Too many refs given
unknownIoErrorStdout=An unknown I/O error occurred on standard output
+unknownExtraArgument=unknown extra argument -X {0} specified
unknownMergeStrategy=unknown merge strategy {0} specified
unknownSubcommand=Unknown subcommand: {0}
unmergedPaths=Unmerged paths:
@@ -226,6 +228,7 @@ updating=Updating {0}..{1}
usage_Aggressive=This option will cause gc to more aggressively optimize the repository at the expense of taking much more time
usage_AlwaysFallback=Show uniquely abbreviated commit object as fallback
usage_bareClone=Make a bare Git repository. That is, instead of creating [DIRECTORY] and placing the administrative files in [DIRECTORY]/.git, make the [DIRECTORY] itself the $GIT_DIR.
+usage_extraArgument=Pass an extra argument to a merge driver. Currently supported are "-X ours" and "-X theirs".
usage_mirrorClone=Set up a mirror of the source repository. This implies --bare. Compared to --bare, --mirror not only maps \
local branches of the source to local branches of the target, it maps all refs (including remote-tracking branches, notes etc.) \
and sets up a refspec configuration such that all these refs are overwritten by a git remote update in the target repository.
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java
index fdc449e063..ca4877fb34 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java
@@ -24,6 +24,7 @@ import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.merge.ContentMergeStrategy;
import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
import org.eclipse.jgit.pgm.internal.CLIText;
@@ -69,6 +70,20 @@ class Merge extends TextBuiltin {
@Option(name = "-m", usage = "usage_message")
private String message;
+ private ContentMergeStrategy contentStrategy = null;
+
+ @Option(name = "--strategy-option", aliases = { "-X" },
+ metaVar = "metaVar_extraArgument", usage = "usage_extraArgument")
+ void extraArg(String name) {
+ if (ContentMergeStrategy.OURS.name().equalsIgnoreCase(name)) {
+ contentStrategy = ContentMergeStrategy.OURS;
+ } else if (ContentMergeStrategy.THEIRS.name().equalsIgnoreCase(name)) {
+ contentStrategy = ContentMergeStrategy.THEIRS;
+ } else {
+ throw die(MessageFormat.format(CLIText.get().unknownExtraArgument, name));
+ }
+ }
+
/** {@inheritDoc} */
@Override
protected void run() {
@@ -96,8 +111,11 @@ class Merge extends TextBuiltin {
Ref oldHead = getOldHead();
MergeResult result;
try (Git git = new Git(db)) {
- MergeCommand mergeCmd = git.merge().setStrategy(mergeStrategy)
- .setSquash(squash).setFastForward(ff)
+ MergeCommand mergeCmd = git.merge()
+ .setStrategy(mergeStrategy)
+ .setContentMergeStrategy(contentStrategy)
+ .setSquash(squash)
+ .setFastForward(ff)
.setCommit(!noCommit);
if (srcRef != null) {
mergeCmd.include(srcRef);
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java
index 991b3ba58a..8e49a76a33 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java
@@ -284,6 +284,7 @@ public class CLIText extends TranslationBundle {
/***/ public String tooManyRefsGiven;
/***/ public String treeIsRequired;
/***/ public char[] unknownIoErrorStdout;
+ /***/ public String unknownExtraArgument;
/***/ public String unknownMergeStrategy;
/***/ public String unknownSubcommand;
/***/ public String unmergedPaths;