summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.junit/src
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2010-12-28 17:15:18 +0100
committerRobin Rosenberg <robin.rosenberg@dewire.com>2010-12-31 11:48:34 +0100
commit797ebba30707259f7a4bc06baa40360ab79d2ff8 (patch)
treeea089758d503ecacccdd0adfa409c292681f3c71 /org.eclipse.jgit.junit/src
parent240769e023c4ea6c8394c25d58fdca7f0bb82948 (diff)
downloadjgit-797ebba30707259f7a4bc06baa40360ab79d2ff8.tar.gz
jgit-797ebba30707259f7a4bc06baa40360ab79d2ff8.zip
Add support for getting the system wide configuration
These settings are stored in <prefix>/etc/gitconfig. The C Git binary is installed in <prefix>/bin, so we look for the C Git executable to find this location, first by looking at the PATH environment variable and then by attemting to launch bash as a login shell to find out. Bug: 333216 Change-Id: I1bbee9fb123a81714a34a9cc242b92beacfbb4a8 Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
Diffstat (limited to 'org.eclipse.jgit.junit/src')
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java43
1 files changed, 31 insertions, 12 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java
index 5c2e77f673..b53dce2161 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java
@@ -45,39 +45,50 @@
package org.eclipse.jgit.junit;
+import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.SystemReader;
public class MockSystemReader extends SystemReader {
+ private final class MockConfig extends FileBasedConfig {
+ private MockConfig(File cfgLocation, FS fs) {
+ super(cfgLocation, fs);
+ }
+
+ @Override
+ public void load() throws IOException, ConfigInvalidException {
+ // Do nothing
+ }
+
+ @Override
+ public boolean isOutdated() {
+ return false;
+ }
+ }
+
final Map<String, String> values = new HashMap<String, String>();
FileBasedConfig userGitConfig;
+ FileBasedConfig systemGitConfig;
+
public MockSystemReader() {
init(Constants.OS_USER_NAME_KEY);
init(Constants.GIT_AUTHOR_NAME_KEY);
init(Constants.GIT_AUTHOR_EMAIL_KEY);
init(Constants.GIT_COMMITTER_NAME_KEY);
init(Constants.GIT_COMMITTER_EMAIL_KEY);
- userGitConfig = new FileBasedConfig(null, null) {
- @Override
- public void load() throws IOException, ConfigInvalidException {
- // Do nothing
- }
-
- @Override
- public boolean isOutdated() {
- return false;
- }
- };
+ userGitConfig = new MockConfig(null, null);
+ systemGitConfig = new MockConfig(null, null);
}
private void init(final String n) {
@@ -103,11 +114,18 @@ public class MockSystemReader extends SystemReader {
}
@Override
- public FileBasedConfig openUserConfig(FS fs) {
+ public FileBasedConfig openUserConfig(Config parent, FS fs) {
+ assert parent == null || parent == systemGitConfig;
return userGitConfig;
}
@Override
+ public FileBasedConfig openSystemConfig(Config parent, FS fs) {
+ assert parent == null;
+ return systemGitConfig;
+ }
+
+ @Override
public String getHostname() {
return "fake.host.example.com";
}
@@ -121,4 +139,5 @@ public class MockSystemReader extends SystemReader {
public int getTimezone(long when) {
return TimeZone.getTimeZone("GMT-03:30").getOffset(when) / (60 * 1000);
}
+
}