diff options
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java | 78 |
1 files changed, 75 insertions, 3 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java index 04d91af4b0..2d3a6e1877 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java @@ -63,6 +63,7 @@ import org.eclipse.jgit.api.errors.WrongRepositoryStateException; import org.eclipse.jgit.dircache.DirCacheCheckout; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.AnyObjectId; +import org.eclipse.jgit.lib.Config.ConfigEnum; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectIdRef; @@ -81,6 +82,7 @@ import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalkUtils; import org.eclipse.jgit.treewalk.FileTreeIterator; +import org.eclipse.jgit.util.StringUtils; /** * A class used to execute a {@code Merge} command. It has setters for all @@ -102,10 +104,11 @@ public class MergeCommand extends GitCommand<MergeResult> { private FastForwardMode fastForwardMode = FastForwardMode.FF; /** - * The modes available for fast forward merges (corresponding to the --ff, - * --no-ff and --ff-only options). + * The modes available for fast forward merges corresponding to the + * <code>--ff</code>, <code>--no-ff</code> and <code>--ff-only</code> + * options under <code>branch.<name>.mergeoptions</code>. */ - public enum FastForwardMode { + public enum FastForwardMode implements ConfigEnum { /** * Corresponds to the default --ff option (for a fast forward update the * branch pointer only). @@ -121,6 +124,75 @@ public class MergeCommand extends GitCommand<MergeResult> { * forward). */ FF_ONLY; + + public String toConfigValue() { + return "--" + name().toLowerCase().replace('_', '-'); //$NON-NLS-1$ + } + + public boolean matchConfigValue(String in) { + if (StringUtils.isEmptyOrNull(in)) + return false; + if (!in.startsWith("--")) //$NON-NLS-1$ + return false; + return name().equalsIgnoreCase(in.substring(2).replace('-', '_')); + } + + /** + * The modes available for fast forward merges corresponding to the + * options under <code>merge.ff</code>. + */ + public enum Merge { + /** + * {@link FastForwardMode#FF}. + */ + TRUE, + /** + * {@link FastForwardMode#NO_FF}. + */ + FALSE, + /** + * {@link FastForwardMode#FF_ONLY}. + */ + ONLY; + + /** + * Map from <code>FastForwardMode</code> to + * <code>FastForwardMode.Merge</code>. + * + * @param ffMode + * the <code>FastForwardMode</code> value to be mapped + * @return the mapped code>FastForwardMode.Merge</code> value + */ + public static Merge valueOf(FastForwardMode ffMode) { + switch (ffMode) { + case NO_FF: + return FALSE; + case FF_ONLY: + return ONLY; + default: + return TRUE; + } + } + } + + /** + * Map from <code>FastForwardMode.Merge</code> to + * <code>FastForwardMode</code>. + * + * @param ffMode + * the <code>FastForwardMode.Merge</code> value to be mapped + * @return the mapped code>FastForwardMode</code> value + */ + public static FastForwardMode valueOf(FastForwardMode.Merge ffMode) { + switch (ffMode) { + case FALSE: + return NO_FF; + case ONLY: + return FF_ONLY; + default: + return FF; + } + } } /** |