summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorThomas Wolf <twolf@apache.org>2023-10-08 21:47:05 +0200
committerThomas Wolf <twolf@apache.org>2023-10-14 23:33:10 +0200
commitecf94d1595c23b410d460e05a0d0bba60a443cd7 (patch)
treea6c1ef2b8c690b91b507b66e6bdcf824486e45a3 /org.eclipse.jgit.test/tst
parentf93ccb7fd4c619d5eeeb6fb46ca20fce73c597a0 (diff)
downloadjgit-ecf94d1595c23b410d460e05a0d0bba60a443cd7.tar.gz
jgit-ecf94d1595c23b410d460e05a0d0bba60a443cd7.zip
Config.removeSection() telling whether it changed the config
Add a variant of unsetSection() that returns whether it did indeed change the config. This can be used in to skip saving the config if it was not changed. Also fix the iteration over the entries: lastWasMatch was never reset, and thus all empty lines after a match would be removed. Change-Id: Iea9e84aa74b1e4bb3c89efe3936fa3a8a09532e5 Signed-off-by: Thomas Wolf <twolf@apache.org>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java40
1 files changed, 38 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
index 36cf77bb01..0c0257df90 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
@@ -507,6 +507,35 @@ public class ConfigTest {
}
@Test
+ public void testRemoveBranchSection() throws ConfigInvalidException {
+ Config c = parse("" //
+ + "[branch \"keep\"]\n"
+ + " merge = master.branch.to.keep.in.the.file\n"
+ + "\n"
+ + "[branch \"remove\"]\n"
+ + " merge = this.will.get.deleted\n"
+ + " remote = origin-for-some-long-gone-place\n"
+ + "\n"
+ + "\n"
+ + "[core-section-not-to-remove-in-test]\n"
+ + " packedGitLimit = 14\n"
+ + "\n"
+ + "[other]\n"
+ + " foo = bar\n");
+ assertFalse(c.removeSection("branch", "does.not.exist"));
+ assertTrue(c.removeSection("branch", "remove"));
+ assertEquals("" //
+ + "[branch \"keep\"]\n"
+ + " merge = master.branch.to.keep.in.the.file\n"
+ + "\n"
+ + "[core-section-not-to-remove-in-test]\n"
+ + " packedGitLimit = 14\n"
+ + "\n"
+ + "[other]\n"
+ + " foo = bar\n", c.toText());
+ }
+
+ @Test
public void testUnsetBranchSection() throws ConfigInvalidException {
Config c = parse("" //
+ "[branch \"keep\"]\n"
@@ -516,8 +545,12 @@ public class ConfigTest {
+ " merge = this.will.get.deleted\n"
+ " remote = origin-for-some-long-gone-place\n"
+ "\n"
+ + "\n"
+ "[core-section-not-to-remove-in-test]\n"
- + " packedGitLimit = 14\n");
+ + " packedGitLimit = 14\n"
+ + "\n"
+ + "[other]\n"
+ + " foo = bar\n");
c.unsetSection("branch", "does.not.exist");
c.unsetSection("branch", "remove");
assertEquals("" //
@@ -525,7 +558,10 @@ public class ConfigTest {
+ " merge = master.branch.to.keep.in.the.file\n"
+ "\n"
+ "[core-section-not-to-remove-in-test]\n"
- + " packedGitLimit = 14\n", c.toText());
+ + " packedGitLimit = 14\n"
+ + "\n"
+ + "[other]\n"
+ + " foo = bar\n", c.toText());
}
@Test