summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.junit
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2019-10-07 17:58:56 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2019-11-09 18:01:19 +0100
commit838b5a84b5093c335b95a644b8888006d9e95493 (patch)
tree3443d1fd7052bee0e128237eca54a7d7ad5fb5ac /org.eclipse.jgit.junit
parentffe74210d64550d5e731d1179567b4fdc746fd7a (diff)
downloadjgit-838b5a84b5093c335b95a644b8888006d9e95493.tar.gz
jgit-838b5a84b5093c335b95a644b8888006d9e95493.zip
Store filesystem timestamp resolution in extra jgit config
This avoids polluting hand-crafted user level config with auto-configured options which might disturb in environments where the user level config is replicated between different machines. Add a jgit config as parent of the system level config. Persist measured timestamp resolutions always in this jgit config and read it via the user global config. This has the effect that auto-configured timestamp resolution will be used by default and can be overridden in either the system level or user level config. Store the jgit config under the XDG_CONFIG_HOME directory following the XDG base directory specification [1] in order to ensure that we have write permissions to persist the file. This has the effect that each OS user will use its jgit config since they typically use different XDG_CONFIG_HOME directories. If the environment variable XDG_CONFIG_HOME is defined the jgit config file is located at $XDG_CONFIG_HOME/jgit/config otherwise the default is ~/.config/jgit/config. If you want to avoid redundant measurement for different OS users manually copy the values measured and auto-configured for one OS user to the system level git config. [1] https://wiki.archlinux.org/index.php/XDG_Base_Directory Bug: 551850 Change-Id: I0022bd40ae62f82e5b964c2ea25822eb55d94687 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.junit')
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java12
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java23
2 files changed, 33 insertions, 2 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
index 5c2cd6ac65..eca8179ece 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
@@ -125,8 +125,9 @@ public abstract class LocalDiskRepositoryTestCase {
public void setUp() throws Exception {
tmp = File.createTempFile("jgit_test_", "_tmp");
CleanupThread.deleteOnShutdown(tmp);
- if (!tmp.delete() || !tmp.mkdir())
+ if (!tmp.delete() || !tmp.mkdir()) {
throw new IOException("Cannot create " + tmp);
+ }
mockSystemReader = new MockSystemReader();
SystemReader.setInstance(mockSystemReader);
@@ -137,7 +138,11 @@ public abstract class LocalDiskRepositoryTestCase {
// the same one here
FS.getFileStoreAttributes(tmp.toPath().getParent());
- FileBasedConfig userConfig = new FileBasedConfig(
+ FileBasedConfig jgitConfig = new FileBasedConfig(
+ new File(tmp, "jgitconfig"), FS.DETECTED);
+ FileBasedConfig systemConfig = new FileBasedConfig(jgitConfig,
+ new File(tmp, "systemgitconfig"), FS.DETECTED);
+ FileBasedConfig userConfig = new FileBasedConfig(systemConfig,
new File(tmp, "usergitconfig"), FS.DETECTED);
// We have to set autoDetach to false for tests, because tests expect to be able
// to clean up by recursively removing the repository, and background GC might be
@@ -145,7 +150,10 @@ public abstract class LocalDiskRepositoryTestCase {
userConfig.setBoolean(ConfigConstants.CONFIG_GC_SECTION,
null, ConfigConstants.CONFIG_KEY_AUTODETACH, false);
userConfig.save();
+ mockSystemReader.setJGitConfig(jgitConfig);
+ mockSystemReader.setSystemGitConfig(systemConfig);
mockSystemReader.setUserGitConfig(userConfig);
+
ceilTestDirectories(getCeilings());
author = new PersonIdent("J. Author", "jauthor@example.com");
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 13c2932282..630c8a4799 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
@@ -103,6 +103,8 @@ public class MockSystemReader extends SystemReader {
private FileBasedConfig userGitConfig;
+ private FileBasedConfig jgitConfig;
+
FileBasedConfig systemGitConfig;
/**
@@ -119,6 +121,16 @@ public class MockSystemReader extends SystemReader {
}
/**
+ * Set the jgit config stored at $XDG_CONFIG_HOME/jgit/config
+ *
+ * @param jgitConfig
+ * set the jgit configuration
+ */
+ public void setJGitConfig(FileBasedConfig jgitConfig) {
+ this.jgitConfig = jgitConfig;
+ }
+
+ /**
* Set the system-level git config
*
* @param systemGitConfig
@@ -142,6 +154,7 @@ public class MockSystemReader extends SystemReader {
init(Constants.GIT_COMMITTER_EMAIL_KEY);
setProperty(Constants.OS_USER_DIR, ".");
userGitConfig = new MockConfig(null, null);
+ jgitConfig = new MockConfig(null, null);
systemGitConfig = new MockConfig(null, null);
setCurrentPlatform();
}
@@ -200,6 +213,11 @@ public class MockSystemReader extends SystemReader {
}
@Override
+ public FileBasedConfig getJGitConfig() {
+ return jgitConfig;
+ }
+
+ @Override
public StoredConfig getSystemConfig()
throws IOException, ConfigInvalidException {
return systemGitConfig;
@@ -333,4 +351,9 @@ public class MockSystemReader extends SystemReader {
return "MockSystemReader";
}
+ @Override
+ public FileBasedConfig openJGitConfig(Config parent, FS fs) {
+ return jgitConfig;
+ }
+
}