diff options
author | Marc Strapetz <marc.strapetz@syntevo.com> | 2018-08-25 11:33:50 +0200 |
---|---|---|
committer | Marc Strapetz <marc.strapetz@syntevo.com> | 2018-09-20 17:05:39 +0200 |
commit | f5614d471d6d4b8eb54dd3ef8e457317dfd26530 (patch) | |
tree | 43c97c56b0d137bdb00de1b9c868d83641216520 /org.eclipse.jgit.test/tst/org/eclipse/jgit/storage | |
parent | 31abb329b42f3bab4d683bd1c709ab55f0d29ef6 (diff) | |
download | jgit-f5614d471d6d4b8eb54dd3ef8e457317dfd26530.tar.gz jgit-f5614d471d6d4b8eb54dd3ef8e457317dfd26530.zip |
Don't inline included configs on FileBasedConfig.save()
Bug: 529825
Change-Id: Id23d4602aa2082d7f2dfe15ae92d7b175b1b8944
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/storage')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java | 52 |
1 files changed, 52 insertions, 0 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 7f0d60295c..777a784c33 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 @@ -52,6 +52,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.util.StringTokenizer; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.util.FS; @@ -67,16 +68,23 @@ public class FileBasedConfigTest { private static final String NAME = "name"; + private static final String EMAIL = "email"; + private static final String ALICE = "Alice"; private static final String BOB = "Bob"; + private static final String ALICE_EMAIL = "alice@home"; + private static final String CONTENT1 = "[" + USER + "]\n\t" + NAME + " = " + ALICE + "\n"; private static final String CONTENT2 = "[" + USER + "]\n\t" + NAME + " = " + BOB + "\n"; + private static final String CONTENT3 = "[" + USER + "]\n\t" + NAME + " = " + + ALICE + "\n" + "[" + USER + "]\n\t" + EMAIL + " = " + ALICE_EMAIL; + private File trash; @Before @@ -233,6 +241,50 @@ public class FileBasedConfigTest { assertEquals(ALICE, config.getString(USER, null, NAME)); } + @Test + public void testIncludeDontInlineIncludedLinesOnSave() + throws IOException, ConfigInvalidException { + // use a content with multiple sections and multiple key/value pairs + // because code for first line works different than for subsequent lines + final File includedFile = createFile(CONTENT3.getBytes(), "dir1"); + + final File file = createFile(new byte[0], "dir2"); + FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED); + config.setString("include", null, "path", + ("../" + includedFile.getParentFile().getName() + "/" + + includedFile.getName())); + + // just by setting the include.path, it won't be included + assertEquals(null, config.getString(USER, null, NAME)); + assertEquals(null, config.getString(USER, null, EMAIL)); + config.save(); + + // and it won't be included after saving + assertEquals(null, config.getString(USER, null, NAME)); + assertEquals(null, config.getString(USER, null, EMAIL)); + + final String expectedText = config.toText(); + assertEquals(2, + new StringTokenizer(expectedText, "\n", false).countTokens()); + + config = new FileBasedConfig(file, FS.DETECTED); + config.load(); + + String actualText = config.toText(); + assertEquals(expectedText, actualText); + // but it will be included after (re)loading + assertEquals(ALICE, config.getString(USER, null, NAME)); + assertEquals(ALICE_EMAIL, config.getString(USER, null, EMAIL)); + + config.save(); + + actualText = config.toText(); + assertEquals(expectedText, actualText); + // and of course preserved after saving + assertEquals(ALICE, config.getString(USER, null, NAME)); + assertEquals(ALICE_EMAIL, config.getString(USER, null, EMAIL)); + } + private File createFile(byte[] content) throws IOException { return createFile(content, null); } |