summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorLuca Milanesio <luca.milanesio@gmail.com>2021-12-28 23:53:35 +0000
committerMatthias Sohn <matthias.sohn@sap.com>2021-12-30 11:14:47 +0100
commitfed0ab9baad30a58bfae30ce8b45e5ba3b1b1a10 (patch)
treecc060c190885b653ab319fd686d8d0536962cb73 /org.eclipse.jgit.test
parent7828ef349cfb671cf9673d766a420c032d7ffb45 (diff)
downloadjgit-fed0ab9baad30a58bfae30ce8b45e5ba3b1b1a10.tar.gz
jgit-fed0ab9baad30a58bfae30ce8b45e5ba3b1b1a10.zip
Use FileSnapshot without using configs for FileBasedConfigstable-5.1
FileBasedConfig should not rely on auto-detection of the file-snapshot attribute computation based on config. The check was already performed when a new FileBasedConfig is created at L158: // don't use config in this snapshot to avoid endless recursion newSnapshot = FileSnapshot.saveNoConfig(getFile()); The check was missing though when the FileBasedConfig is saved to disk and the new snapshot is obtained from the associated LockFile. This change fixes the issue by keeping a non-config based FileSnapshot also after a FileBasedConfig is saved. Bug: 577983 Change-Id: Id1e410ba687e683ff2b2643af31e1110b103b356
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 f3cd61da69..cfb2735a04 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
@@ -46,6 +46,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;
@@ -53,6 +54,8 @@ import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.junit.MockSystemReader;
@@ -82,11 +85,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
@@ -245,6 +250,37 @@ public class FileBasedConfigTest {
assertEquals(ALICE, config.getString(USER, null, NAME));
}
+ @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);
}