diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java index 557aa8e03..a46dc33cd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java @@ -157,6 +157,8 @@ public abstract class FS { private volatile Holder userHome; + private volatile Holder gitSystemConfig; + /** * Constructs a file system abstraction. */ @@ -172,6 +174,7 @@ public abstract class FS { */ protected FS(FS src) { userHome = src.userHome; + gitSystemConfig = src.gitSystemConfig; } /** @return a new instance of the same type of FS. */ @@ -547,6 +550,31 @@ public abstract class FS { return new File(w); } + /** + * @return the currently used path to the system-wide Git configuration + * file or {@code null} if none has been set. + * @since 4.0 + */ + public File getGitSystemConfig() { + if (gitSystemConfig == null) { + gitSystemConfig = new Holder(discoverGitSystemConfig()); + } + return gitSystemConfig.value; + } + + /** + * Set the path to the system-wide Git configuration file to use. + * + * @param configFile + * the path to the config file. + * @return {@code this} + * @since 4.0 + */ + public FS setGitSystemConfig(File configFile) { + gitSystemConfig = new Holder(configFile); + return this; + } + /** * @param grandchild * @return the parent directory of this file's parent directory or diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java index 04a7051a7..b4233b6cc 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java @@ -89,7 +89,7 @@ public abstract class SystemReader { } public FileBasedConfig openSystemConfig(Config parent, FS fs) { - File configFile = fs.discoverGitSystemConfig(); + File configFile = fs.getGitSystemConfig(); if (configFile == null) { return new FileBasedConfig(null, fs) { public void load() {