Browse Source

Config load should not fail on unsupported or nonexistent include path

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>
tags/v4.4.1.201607150455-r
Hugo Arès 8 years ago
parent
commit
80cd855443

+ 24
- 3
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java View File



@Test @Test
public void testIncludeValuePathNotFound() throws ConfigInvalidException { public void testIncludeValuePathNotFound() throws ConfigInvalidException {
// we do not expect an exception, included path not found are ignored
String notFound = "/not/found"; 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 @Test

+ 0
- 1
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties View File

invalidIdLength=Invalid id length {0}; should be {1} invalidIdLength=Invalid id length {0}; should be {1}
invalidIgnoreParamSubmodule=Found invalid ignore param for submodule {0}. invalidIgnoreParamSubmodule=Found invalid ignore param for submodule {0}.
invalidIgnoreRule=Exception caught while parsing ignore rule ''{0}''. invalidIgnoreRule=Exception caught while parsing ignore rule ''{0}''.
invalidIncludedPathInConfigFile=Invalid included path in config file: {0}
invalidIntegerValue=Invalid integer value: {0}.{1}={2} invalidIntegerValue=Invalid integer value: {0}.{1}={2}
invalidKey=Invalid key: {0} invalidKey=Invalid key: {0}
invalidLineInConfigFile=Invalid line in config file invalidLineInConfigFile=Invalid line in config file

+ 0
- 1
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java View File

/***/ public String invalidIdLength; /***/ public String invalidIdLength;
/***/ public String invalidIgnoreParamSubmodule; /***/ public String invalidIgnoreParamSubmodule;
/***/ public String invalidIgnoreRule; /***/ public String invalidIgnoreRule;
/***/ public String invalidIncludedPathInConfigFile;
/***/ public String invalidIntegerValue; /***/ public String invalidIntegerValue;
/***/ public String invalidKey; /***/ public String invalidKey;
/***/ public String invalidLineInConfigFile; /***/ public String invalidLineInConfigFile;

+ 9
- 2
org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java View File

package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;


import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
decoded = RawParseUtils.decode(bytes); decoded = RawParseUtils.decode(bytes);
} }
newEntries.addAll(fromTextRecurse(decoded, depth + 1)); 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) { } catch (IOException ioe) {
throw new ConfigInvalidException(MessageFormat.format(
JGitText.get().invalidIncludedPathInConfigFile, path));
throw new ConfigInvalidException(
MessageFormat.format(JGitText.get().cannotReadFile, path),
ioe);
} }
} }



Loading…
Cancel
Save