diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2021-12-30 23:41:54 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2021-12-30 23:41:54 +0100 |
commit | d87e5e07a542ff40b3fb3e3ca02c170a127b9e2a (patch) | |
tree | 4b128264cf2a0d0daeeb065b7e1e2614dc3526a5 /org.eclipse.jgit.test/tst/org | |
parent | fd612a12821910f7fbfca88e2f9b0b955e2845f0 (diff) | |
parent | 7f51f8acd8a0e09cef2d96ff2eabbb2da8ea5176 (diff) | |
download | jgit-d87e5e07a542ff40b3fb3e3ca02c170a127b9e2a.tar.gz jgit-d87e5e07a542ff40b3fb3e3ca02c170a127b9e2a.zip |
Merge branch 'stable-5.4' into stable-5.5stable-5.5
* stable-5.4:
Use FileSnapshot without using configs for FileBasedConfig
Change-Id: I84e11bdaa9306e23212dac9d8670557a18d40107
Diffstat (limited to 'org.eclipse.jgit.test/tst/org')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java | 40 |
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 5100d258d7..8b9869ae4a 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; @@ -54,6 +55,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; @@ -90,11 +93,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 @@ -298,6 +303,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); } |