aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2021-12-31 00:05:40 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2021-12-31 00:05:40 +0100
commit95bf9bbfe80d13399447a8d09ee19dc7c7705366 (patch)
tree8f2c6ca8a219ce179cde2ff669b37f3a881aa7e2 /org.eclipse.jgit.test
parent8a9b4972b42d65af0f859ea5d5b3447677bc2992 (diff)
parentc6b0ee04e49c96e0beec4154196c416abcf2bcc9 (diff)
downloadjgit-95bf9bbfe80d13399447a8d09ee19dc7c7705366.tar.gz
jgit-95bf9bbfe80d13399447a8d09ee19dc7c7705366.zip
Merge branch 'stable-5.9' into stable-5.10
* stable-5.9: Use FileSnapshot without using configs for FileBasedConfig Change-Id: I4f954c48ad6e8ff18826fdc72d225bff3e3ae2d9
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java40
1 files changed, 38 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java
index 803ff108f8..1ccacd75e2 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java
@@ -13,6 +13,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.util.FileUtils.pathToString;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -21,6 +22,8 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.StringTokenizer;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.junit.MockSystemReader;
@@ -57,11 +60,13 @@ public class FileBasedConfigTest {
private Path trash;
+ private MockSystemReader mockSystemReader;
+
@Before
public void setUp() throws Exception {
- SystemReader.setInstance(new MockSystemReader());
+ mockSystemReader = new MockSystemReader();
+ SystemReader.setInstance(mockSystemReader);
trash = Files.createTempDirectory("tmp_");
- FS.getFileStoreAttributes(trash.getParent());
}
@After
@@ -265,6 +270,37 @@ public class FileBasedConfigTest {
assertEquals(ALICE_EMAIL, config.getString(USER, null, EMAIL));
}
+ @Test
+ public void testSavedConfigFileShouldNotReadUserGitConfig()
+ throws IOException {
+ AtomicBoolean userConfigTimeRead = new AtomicBoolean(false);
+
+ Path userConfigFile = createFile(CONTENT1.getBytes(), "home");
+ mockSystemReader.setUserGitConfig(
+ new FileBasedConfig(userConfigFile.toFile(), FS.DETECTED) {
+
+ @Override
+ public long getTimeUnit(String section, String subsection,
+ String name, long defaultValue, TimeUnit wantUnit) {
+ userConfigTimeRead.set(true);
+ return super.getTimeUnit(section, subsection, name,
+ defaultValue, wantUnit);
+ }
+ });
+
+ Path file = createFile(CONTENT2.getBytes(), "repo");
+ FileBasedConfig fileBasedConfig = new FileBasedConfig(file.toFile(),
+ FS.DETECTED);
+ fileBasedConfig.save();
+
+ // Needed to trigger the read of FileSnapshot filesystem settings
+ fileBasedConfig.isOutdated();
+ assertFalse(
+ "User config should not be read when accessing config files "
+ + "for avoiding deadlocks",
+ userConfigTimeRead.get());
+ }
+
private Path createFile(byte[] content) throws IOException {
return createFile(content, null);
}