FS: Allow to manually set the path to the Git system config file

Now that d7a4473 removed the gitprefix property, we did not have a way to
specify the path to the Git system config file in case
discoverGitSystemConfig() fails. Fix that by introducing a member variable
that caches the result of discoverGitSystemConfig() as well as a setter
method to overwrite the content of that variable.

Change-Id: Icd965bffbe2f11b18c9505ee2ddd2afad5b64d70
Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
This commit is contained in:
Sebastian Schuberth 2015-05-22 17:21:27 +02:00 committed by Matthias Sohn
parent 9599f3f1a6
commit 7ce6abe858
2 changed files with 29 additions and 1 deletions

View File

@ -157,6 +157,8 @@ public static FS detect(Boolean cygwinUsed) {
private volatile Holder<File> userHome; private volatile Holder<File> userHome;
private volatile Holder<File> gitSystemConfig;
/** /**
* Constructs a file system abstraction. * Constructs a file system abstraction.
*/ */
@ -172,6 +174,7 @@ protected FS() {
*/ */
protected FS(FS src) { protected FS(FS src) {
userHome = src.userHome; userHome = src.userHome;
gitSystemConfig = src.gitSystemConfig;
} }
/** @return a new instance of the same type of FS. */ /** @return a new instance of the same type of FS. */
@ -547,6 +550,31 @@ protected File discoverGitSystemConfig() {
return new File(w); 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<File>(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<File>(configFile);
return this;
}
/** /**
* @param grandchild * @param grandchild
* @return the parent directory of this file's parent directory or * @return the parent directory of this file's parent directory or

View File

@ -89,7 +89,7 @@ public String getProperty(String key) {
} }
public FileBasedConfig openSystemConfig(Config parent, FS fs) { public FileBasedConfig openSystemConfig(Config parent, FS fs) {
File configFile = fs.discoverGitSystemConfig(); File configFile = fs.getGitSystemConfig();
if (configFile == null) { if (configFile == null) {
return new FileBasedConfig(null, fs) { return new FileBasedConfig(null, fs) {
public void load() { public void load() {