aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2021-12-31 00:29:40 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2021-12-31 00:29:40 +0100
commitc8ab1392d16ffa274501ab7420fe05bb743eca34 (patch)
tree27e6b57b093f5f4e6b81fb77bfee315f7302cbf0 /org.eclipse.jgit.test/tst/org/eclipse
parent41406e278fb69df1dbf4dcb9a82dcb03f2a8d5d7 (diff)
parent44bad3d98e9fe41fc103b6981ec3c623ef9388f3 (diff)
downloadjgit-c8ab1392d16ffa274501ab7420fe05bb743eca34.tar.gz
jgit-c8ab1392d16ffa274501ab7420fe05bb743eca34.zip
Merge branch 'stable-5.12' into stable-5.13
* stable-5.12: Use FileSnapshot without using configs for FileBasedConfig Change-Id: I6a0266cbcaaf18d0d60f0abecb5434fd919c44b7
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse')
-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 b8b503cdcd..7f0bfefbe7 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
@@ -14,6 +14,7 @@ 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.assertNotNull;
+import static org.junit.Assert.assertFalse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -22,6 +23,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;
@@ -58,11 +61,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
@@ -266,6 +271,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);
}