]> source.dussan.org Git - jgit.git/commitdiff
Fix config value get to return last instead of 1st just like git 96/72296/4
authorMarco Miller <marco.miller@ericsson.com>
Fri, 6 May 2016 20:19:42 +0000 (16:19 -0400)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 11 May 2016 22:26:38 +0000 (00:26 +0200)
Before this fix, getting the value of 'key' below used to return
value1. This fix makes it so that value3 gets returned instead,
just like native git's get.

[section]
  key = value1
  key = value2
  key = value3

Change-Id: Iccb24de9b63c3ad8646c909494ca3f8c9ed6e29c
Signed-off-by: Marco Miller <marco.miller@ericsson.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java

index 6238a354d8ce4999177191b1fa39a1065c8967f1..6c6100e11699c837d56e88a071d76bff3107e04c 100644 (file)
@@ -739,6 +739,12 @@ public class ConfigTest {
                                c.getStringList("a", null, "x"));
        }
 
+       @Test
+       public void testReadMultipleValuesForName() throws ConfigInvalidException {
+               Config c = parse("[foo]\nbar=false\nbar=true\n");
+               assertTrue(c.getBoolean("foo", "bar", false));
+       }
+
        private static void assertReadLong(long exp) throws ConfigInvalidException {
                assertReadLong(exp, String.valueOf(exp));
        }
index 567e31642d07398dc1a08402aca27accd0ccfae9..70c3997d522ad27f6e29756c30682ce327bb0214 100644 (file)
@@ -633,12 +633,13 @@ public class Config {
        private String getRawString(final String section, final String subsection,
                        final String name) {
                String[] lst = getRawStringList(section, subsection, name);
-               if (lst != null)
-                       return lst[0];
-               else if (baseConfig != null)
+               if (lst != null) {
+                       return lst[lst.length - 1];
+               } else if (baseConfig != null) {
                        return baseConfig.getRawString(section, subsection, name);
-               else
+               } else {
                        return null;
+               }
        }
 
        private String[] getRawStringList(String section, String subsection,