]> source.dussan.org Git - jgit.git/commitdiff
Config load should not fail on unsupported or nonexistent include path 46/75346/4
authorHugo Arès <hugo.ares@ericsson.com>
Wed, 15 Jun 2016 18:40:05 +0000 (14:40 -0400)
committerHugo Arès <hugo.ares@ericsson.com>
Mon, 27 Jun 2016 12:59:03 +0000 (08:59 -0400)
1f86350 added initial support for include.path. Relative path and path
with tilde are not yet supported but config load was failing if one of
those 2 unsupported options was encountered. Another problem was that
config load was failing if the include.path file did not exist.

Change the behavior to be consistent with native git. Ignore unsupported
or nonexistent include.path.

Bug: 495505
Bug: 496732
Change-Id: I7285d0e7abb6389ba6983e9c46021bea4344af68
Signed-off-by: Hugo Arès <hugo.ares@ericsson.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java

index 6d07d34d3a9a48aea9a4498f1fa2a75b20e28f47..c14c6d7f2275960cf01466e693e21f8ed0b6e1f1 100644 (file)
@@ -782,10 +782,31 @@ public class ConfigTest {
 
        @Test
        public void testIncludeValuePathNotFound() throws ConfigInvalidException {
+               // we do not expect an exception, included path not found are ignored
                String notFound = "/not/found";
-               expectedEx.expect(ConfigInvalidException.class);
-               expectedEx.expectMessage(notFound);
-               parse("[include]\npath=" + notFound + "\n");
+               Config parsed = parse("[include]\npath=" + notFound + "\n");
+               assertEquals(1, parsed.getSections().size());
+               assertEquals(notFound, parsed.getString("include", null, "path"));
+       }
+
+       @Test
+       public void testIncludeValuePathWithTilde() throws ConfigInvalidException {
+               // we do not expect an exception, included path not supported are
+               // ignored
+               String notSupported = "~/someFile";
+               Config parsed = parse("[include]\npath=" + notSupported + "\n");
+               assertEquals(1, parsed.getSections().size());
+               assertEquals(notSupported, parsed.getString("include", null, "path"));
+       }
+
+       @Test
+       public void testIncludeValuePathRelative() throws ConfigInvalidException {
+               // we do not expect an exception, included path not supported are
+               // ignored
+               String notSupported = "someRelativeFile";
+               Config parsed = parse("[include]\npath=" + notSupported + "\n");
+               assertEquals(1, parsed.getSections().size());
+               assertEquals(notSupported, parsed.getString("include", null, "path"));
        }
 
        @Test
index b71e48b52661fbc896cb30bf27748dadd8ab527c..ead83598650fdd1f35eb4194ccc7642c39515fc7 100644 (file)
@@ -339,7 +339,6 @@ invalidId0=Invalid id
 invalidIdLength=Invalid id length {0}; should be {1}
 invalidIgnoreParamSubmodule=Found invalid ignore param for submodule {0}.
 invalidIgnoreRule=Exception caught while parsing ignore rule ''{0}''.
-invalidIncludedPathInConfigFile=Invalid included path in config file: {0}
 invalidIntegerValue=Invalid integer value: {0}.{1}={2}
 invalidKey=Invalid key: {0}
 invalidLineInConfigFile=Invalid line in config file
index 7c101780a742a55b24b00abf5b36d60fb49fd8c4..a113cd28fc257f33b079a242f150cc0e74c6e425 100644 (file)
@@ -398,7 +398,6 @@ public class JGitText extends TranslationBundle {
        /***/ public String invalidIdLength;
        /***/ public String invalidIgnoreParamSubmodule;
        /***/ public String invalidIgnoreRule;
-       /***/ public String invalidIncludedPathInConfigFile;
        /***/ public String invalidIntegerValue;
        /***/ public String invalidKey;
        /***/ public String invalidLineInConfigFile;
index b8eba3acc2a8ea0a4944cdeaa7ca8933e6eb52e1..6592823da70926f6bf924857080df7655e27b8c5 100644 (file)
@@ -52,6 +52,7 @@
 package org.eclipse.jgit.lib;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.text.MessageFormat;
 import java.util.ArrayList;
@@ -1127,9 +1128,15 @@ public class Config {
                                decoded = RawParseUtils.decode(bytes);
                        }
                        newEntries.addAll(fromTextRecurse(decoded, depth + 1));
+               } catch (FileNotFoundException fnfe) {
+                       if (path.exists()) {
+                               throw new ConfigInvalidException(MessageFormat
+                                               .format(JGitText.get().cannotReadFile, path), fnfe);
+                       }
                } catch (IOException ioe) {
-                       throw new ConfigInvalidException(MessageFormat.format(
-                                       JGitText.get().invalidIncludedPathInConfigFile, path));
+                       throw new ConfigInvalidException(
+                                       MessageFormat.format(JGitText.get().cannotReadFile, path),
+                                       ioe);
                }
        }