summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2010-01-25 10:26:22 -0500
committerCode Review <codereview-daemon@eclipse.org>2010-01-25 10:26:22 -0500
commit6595ab10078690ed448b018383d4ecb538ff2a61 (patch)
treed600f265479f0ea02b92c5ff0efa9531a7a4baaf
parente905d93f9f88bf9a5a549cc1355385ac1029cbb4 (diff)
parent869c8434f6bfa6093299031942026084a5610165 (diff)
downloadjgit-6595ab10078690ed448b018383d4ecb538ff2a61.tar.gz
jgit-6595ab10078690ed448b018383d4ecb538ff2a61.zip
Merge "Don't confuse empty configuration variables with booleans"
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java31
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java7
2 files changed, 34 insertions, 4 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java
index 2cbfc682ca..203b7c8251 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
- * Copyright (C) 2009, Google Inc.
+ * Copyright (C) 2009-2010, Google Inc.
* Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
@@ -242,6 +242,35 @@ public class RepositoryConfigTest extends TestCase {
}
}
+ public void testBooleanWithNoValue() throws ConfigInvalidException {
+ Config c = parse("[my]\n\tempty\n");
+ assertEquals("", c.getString("my", null, "empty"));
+ assertEquals(1, c.getStringList("my", null, "empty").length);
+ assertEquals("", c.getStringList("my", null, "empty")[0]);
+ assertTrue(c.getBoolean("my", "empty", false));
+ assertEquals("[my]\n\tempty\n", c.toText());
+ }
+
+ public void testEmptyString() throws ConfigInvalidException {
+ Config c = parse("[my]\n\tempty =\n");
+ assertNull(c.getString("my", null, "empty"));
+
+ String[] values = c.getStringList("my", null, "empty");
+ assertNotNull(values);
+ assertEquals(1, values.length);
+ assertNull(values[0]);
+
+ // always matches the default, because its non-boolean
+ assertTrue(c.getBoolean("my", "empty", true));
+ assertFalse(c.getBoolean("my", "empty", false));
+
+ assertEquals("[my]\n\tempty =\n", c.toText());
+
+ c = new Config();
+ c.setStringList("my", null, "empty", Arrays.asList(values));
+ assertEquals("[my]\n\tempty =\n", c.toText());
+ }
+
private void assertReadLong(long exp) throws ConfigInvalidException {
assertReadLong(exp, String.valueOf(exp));
}
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 661371ca21..d66aa74c8e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
@@ -715,9 +715,10 @@ public class Config {
if (e.prefix == null || "".equals(e.prefix))
out.append('\t');
out.append(e.name);
- if (e.value != null) {
- if (MAGIC_EMPTY_VALUE != e.value) {
- out.append(" = ");
+ if (MAGIC_EMPTY_VALUE != e.value) {
+ out.append(" =");
+ if (e.value != null) {
+ out.append(' ');
out.append(escapeValue(e.value));
}
}