diff options
5 files changed, 235 insertions, 8 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java index 0d72e639a8..69d7d350cf 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java @@ -124,6 +124,18 @@ public class Main { err.printStackTrace(); System.exit(128); } catch (Exception err) { + // Try to detect errno == EPIPE and exit normally if that happens + // There may be issues with operating system versions and locale, + // but we can probably assume that these messages will not be thrown + // under other circumstances. + if (err.getClass() == IOException.class) { + // Linux, OS X + if (err.getMessage().equals("Broken pipe")) //$NON-NLS-1$ + System.exit(0); + // Windows + if (err.getMessage().equals("The pipe is being closed")) //$NON-NLS-1$ + System.exit(0); + } if (!showStackTrace && err.getCause() != null && err instanceof TransportException) System.err.println(MessageFormat.format(CLIText.get().fatalError, err.getCause().getMessage())); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java index e675609290..9836036237 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java @@ -63,6 +63,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.Set; +import org.eclipse.jgit.api.MergeCommand.FastForwardMode; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.junit.MockSystemReader; import org.eclipse.jgit.util.FS; @@ -287,15 +288,108 @@ public class ConfigTest { assertSame(CoreConfig.AutoCRLF.FALSE, c.getEnum("s", null, "d", CoreConfig.AutoCRLF.FALSE)); - c = parse("[s \"b\"]\n\tc = one two\n"); + c = parse("[s \"b\"]\n\tc = one-two\n"); assertSame(TestEnum.ONE_TWO, c.getEnum("s", "b", "c", TestEnum.ONE_TWO)); } @Test + public void testGetInvalidEnum() throws ConfigInvalidException { + Config c = parse("[a]\n\tb = invalid\n"); + try { + c.getEnum("a", null, "b", TestEnum.ONE_TWO); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("Invalid value: a.b=invalid", e.getMessage()); + } + + c = parse("[a \"b\"]\n\tc = invalid\n"); + try { + c.getEnum("a", "b", "c", TestEnum.ONE_TWO); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("Invalid value: a.b.c=invalid", e.getMessage()); + } + } + + @Test public void testSetEnum() { final Config c = new Config(); c.setEnum("s", "b", "c", TestEnum.ONE_TWO); - assertEquals("[s \"b\"]\n\tc = one two\n", c.toText()); + assertEquals("[s \"b\"]\n\tc = one-two\n", c.toText()); + } + + @Test + public void testGetFastForwardMergeoptions() throws ConfigInvalidException { + Config c = new Config(null); // not set + assertSame(FastForwardMode.MergeOptions.__FF, c.getEnum( + ConfigConstants.CONFIG_BRANCH_SECTION, "side", + ConfigConstants.CONFIG_KEY_MERGEOPTIONS, + FastForwardMode.MergeOptions.__FF)); + c = parse("[branch \"side\"]\n\tmergeoptions = --ff-only\n"); + assertSame(FastForwardMode.MergeOptions.__FF_ONLY, c.getEnum( + ConfigConstants.CONFIG_BRANCH_SECTION, "side", + ConfigConstants.CONFIG_KEY_MERGEOPTIONS, + FastForwardMode.MergeOptions.__FF_ONLY)); + c = parse("[branch \"side\"]\n\tmergeoptions = --ff\n"); + assertSame(FastForwardMode.MergeOptions.__FF, c.getEnum( + ConfigConstants.CONFIG_BRANCH_SECTION, "side", + ConfigConstants.CONFIG_KEY_MERGEOPTIONS, + FastForwardMode.MergeOptions.__FF)); + c = parse("[branch \"side\"]\n\tmergeoptions = --no-ff\n"); + assertSame(FastForwardMode.MergeOptions.__NO_FF, c.getEnum( + ConfigConstants.CONFIG_BRANCH_SECTION, "side", + ConfigConstants.CONFIG_KEY_MERGEOPTIONS, + FastForwardMode.MergeOptions.__NO_FF)); + } + + @Test + public void testSetFastForwardMergeoptions() { + final Config c = new Config(); + c.setEnum("branch", "side", "mergeoptions", + FastForwardMode.MergeOptions.valueOf(FastForwardMode.FF)); + assertEquals("[branch \"side\"]\n\tmergeoptions = --ff\n", c.toText()); + c.setEnum("branch", "side", "mergeoptions", + FastForwardMode.MergeOptions.valueOf(FastForwardMode.FF_ONLY)); + assertEquals("[branch \"side\"]\n\tmergeoptions = --ff-only\n", + c.toText()); + c.setEnum("branch", "side", "mergeoptions", + FastForwardMode.MergeOptions.valueOf(FastForwardMode.NO_FF)); + assertEquals("[branch \"side\"]\n\tmergeoptions = --no-ff\n", + c.toText()); + } + + @Test + public void testGetFastForwardMerge() throws ConfigInvalidException { + Config c = new Config(null); // not set + assertSame(FastForwardMode.Merge.TRUE, c.getEnum( + ConfigConstants.CONFIG_KEY_MERGE, null, + ConfigConstants.CONFIG_KEY_FF, FastForwardMode.Merge.TRUE)); + c = parse("[merge]\n\tff = only\n"); + assertSame(FastForwardMode.Merge.ONLY, c.getEnum( + ConfigConstants.CONFIG_KEY_MERGE, null, + ConfigConstants.CONFIG_KEY_FF, FastForwardMode.Merge.ONLY)); + c = parse("[merge]\n\tff = true\n"); + assertSame(FastForwardMode.Merge.TRUE, c.getEnum( + ConfigConstants.CONFIG_KEY_MERGE, null, + ConfigConstants.CONFIG_KEY_FF, FastForwardMode.Merge.TRUE)); + c = parse("[merge]\n\tff = false\n"); + assertSame(FastForwardMode.Merge.FALSE, c.getEnum( + ConfigConstants.CONFIG_KEY_MERGE, null, + ConfigConstants.CONFIG_KEY_FF, FastForwardMode.Merge.FALSE)); + } + + @Test + public void testSetFastForwardMerge() { + final Config c = new Config(); + c.setEnum("merge", null, "ff", FastForwardMode.Merge.valueOf(FastForwardMode.FF)); + assertEquals("[merge]\n\tff = true\n", c.toText()); + c.setEnum("merge", null, "ff", + FastForwardMode.Merge.valueOf(FastForwardMode.FF_ONLY)); + assertEquals("[merge]\n\tff = only\n", + c.toText()); + c.setEnum("merge", null, "ff", + FastForwardMode.Merge.valueOf(FastForwardMode.NO_FF)); + assertEquals("[merge]\n\tff = false\n", c.toText()); } @Test 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..118e378ce5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java @@ -121,6 +121,122 @@ public class MergeCommand extends GitCommand<MergeResult> { * forward). */ FF_ONLY; + + /** + * The modes available for fast forward merges corresponding to the + * options under branch.<name>.branch config option. + */ + public enum MergeOptions { + /** + * {@link FastForwardMode#FF}. + */ + __FF, + /** + * {@link FastForwardMode#NO_FF}. + */ + __NO_FF, + /** + * {@link FastForwardMode#FF_ONLY}. + */ + __FF_ONLY; + + /** + * Map from <code>FastForwardMode</code> to + * <code>FastForwardMode.MergeOptions</code>. + * + * @param ffMode + * the <code>FastForwardMode</code> value to be mapped + * @return the mapped code>FastForwardMode.MergeOptions</code> value + */ + public static MergeOptions valueOf(FastForwardMode ffMode) { + switch (ffMode) { + case NO_FF: + return __NO_FF; + case FF_ONLY: + return __FF_ONLY; + default: + return __FF; + } + } + } + + /** + * The modes available for fast forward merges corresponding to the + * options under merge.ff config option. + */ + 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; + } + } + + /** + * Map from <code>FastForwardMode.MergeOptions</code> to + * <code>FastForwardMode</code>. + * + * @param ffMode + * the <code>FastForwardMode.MergeOptions</code> value to be + * mapped + * @return the mapped code>FastForwardMode</code> value + */ + public static FastForwardMode valueOf( + FastForwardMode.MergeOptions ffMode) { + switch (ffMode) { + case __NO_FF: + return NO_FF; + case __FF_ONLY: + return FF_ONLY; + default: + return FF; + } + } } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java index 84d77ce32b..fb78d0efff 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java @@ -387,7 +387,7 @@ public class Config { if (value == null) return defaultValue; - String n = value.replace(' ', '_'); + String n = value.replace('-', '_'); T trueState = null; T falseState = null; for (T e : all) { @@ -412,11 +412,13 @@ public class Config { } if (subsection != null) - throw new IllegalArgumentException(MessageFormat.format(JGitText - .get().enumValueNotSupported3, section, name, value)); + throw new IllegalArgumentException(MessageFormat.format( + JGitText.get().enumValueNotSupported3, section, subsection, + name, value)); else - throw new IllegalArgumentException(MessageFormat.format(JGitText - .get().enumValueNotSupported2, section, name, value)); + throw new IllegalArgumentException( + MessageFormat.format(JGitText.get().enumValueNotSupported2, + section, name, value)); } /** @@ -720,7 +722,7 @@ public class Config { */ public <T extends Enum<?>> void setEnum(final String section, final String subsection, final String name, final T value) { - String n = value.name().toLowerCase().replace('_', ' '); + String n = value.name().toLowerCase().replace('_', '-'); setString(section, subsection, name, n); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java index dbaa043e21..8fd84c8938 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java @@ -191,4 +191,7 @@ public class ConfigConstants { /** The "mergeoptions" key */ public static final String CONFIG_KEY_MERGEOPTIONS = "mergeoptions"; + + /** The "ff" key */ + public static final String CONFIG_KEY_FF = "ff"; } |