Browse Source

Save StoredConfig after modifications

When the Config is changed, it should be saved back to its local
file.  This ensure that a future call to getConfig() won't wipe
out the edits that were just made.

Change-Id: Id46d3f85d1c9b377f63ef861b72824e1aa060eee
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.11
Shawn O. Pearce 14 years ago
parent
commit
6f3b4d5d04
  1. 10
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AsIsServiceTest.java
  2. 17
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java
  3. 10
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java
  4. 6
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java
  5. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
  6. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
  7. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
  8. 16
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java

10
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AsIsServiceTest.java

@ -43,6 +43,8 @@
package org.eclipse.jgit.http.test; package org.eclipse.jgit.http.test;
import java.io.IOException;
import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletRequestWrapper;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
@ -51,6 +53,7 @@ import org.eclipse.jgit.http.server.resolver.ServiceNotAuthorizedException;
import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException; import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
public class AsIsServiceTest extends LocalDiskRepositoryTestCase { public class AsIsServiceTest extends LocalDiskRepositoryTestCase {
private Repository db; private Repository db;
@ -87,8 +90,11 @@ public class AsIsServiceTest extends LocalDiskRepositoryTestCase {
service.access(new R("bob", "1.2.3.4"), db); service.access(new R("bob", "1.2.3.4"), db);
} }
public void testCreate_Disabled() throws ServiceNotAuthorizedException { public void testCreate_Disabled() throws ServiceNotAuthorizedException,
db.getConfig().setBoolean("http", null, "getanyfile", false); IOException {
final StoredConfig cfg = db.getConfig();
cfg.setBoolean("http", null, "getanyfile", false);
cfg.save();
try { try {
service.access(new R(null, "1.2.3.4"), db); service.access(new R(null, "1.2.3.4"), db);

17
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java

@ -43,6 +43,8 @@
package org.eclipse.jgit.http.test; package org.eclipse.jgit.http.test;
import java.io.IOException;
import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletRequestWrapper;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
@ -53,6 +55,7 @@ import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.transport.ReceivePack; import org.eclipse.jgit.transport.ReceivePack;
public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase { public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase {
@ -127,8 +130,11 @@ public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase {
assertEquals(author.getWhen(), id.getWhen()); assertEquals(author.getWhen(), id.getWhen());
} }
public void testCreate_Disabled() throws ServiceNotAuthorizedException { public void testCreate_Disabled() throws ServiceNotAuthorizedException,
db.getConfig().setBoolean("http", null, "receivepack", false); IOException {
final StoredConfig cfg = db.getConfig();
cfg.setBoolean("http", null, "receivepack", false);
cfg.save();
try { try {
factory.create(new R(null, "localhost"), db); factory.create(new R(null, "localhost"), db);
@ -153,8 +159,11 @@ public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase {
} }
public void testCreate_Enabled() throws ServiceNotEnabledException, public void testCreate_Enabled() throws ServiceNotEnabledException,
ServiceNotAuthorizedException { ServiceNotAuthorizedException, IOException {
db.getConfig().setBoolean("http", null, "receivepack", true); final StoredConfig cfg = db.getConfig();
cfg.setBoolean("http", null, "receivepack", true);
cfg.save();
ReceivePack rp; ReceivePack rp;
rp = factory.create(new R(null, "1.2.3.4"), db); rp = factory.create(new R(null, "1.2.3.4"), db);

10
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java

@ -43,6 +43,8 @@
package org.eclipse.jgit.http.test; package org.eclipse.jgit.http.test;
import java.io.IOException;
import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletRequestWrapper;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
@ -52,6 +54,7 @@ import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException;
import org.eclipse.jgit.http.server.resolver.UploadPackFactory; import org.eclipse.jgit.http.server.resolver.UploadPackFactory;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.transport.UploadPack; import org.eclipse.jgit.transport.UploadPack;
public class DefaultUploadPackFactoryTest extends LocalDiskRepositoryTestCase { public class DefaultUploadPackFactoryTest extends LocalDiskRepositoryTestCase {
@ -104,8 +107,11 @@ public class DefaultUploadPackFactoryTest extends LocalDiskRepositoryTestCase {
assertSame(db, up.getRepository()); assertSame(db, up.getRepository());
} }
public void testCreate_Disabled() throws ServiceNotAuthorizedException { public void testCreate_Disabled() throws ServiceNotAuthorizedException,
db.getConfig().setBoolean("http", null, "uploadpack", false); IOException {
final StoredConfig cfg = db.getConfig();
cfg.setBoolean("http", null, "uploadpack", false);
cfg.save();
try { try {
factory.create(new R(null, "localhost"), db); factory.create(new R(null, "localhost"), db);

6
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java

@ -68,6 +68,7 @@ import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.storage.file.FileRepository; import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.transport.FetchConnection; import org.eclipse.jgit.transport.FetchConnection;
import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.Transport;
@ -336,8 +337,9 @@ public class HttpClientTests extends HttpTestCase {
public void testListRemote_Smart_UploadPackDisabled() throws Exception { public void testListRemote_Smart_UploadPackDisabled() throws Exception {
FileRepository src = remoteRepository.getRepository(); FileRepository src = remoteRepository.getRepository();
src.getConfig().setBoolean("http", null, "uploadpack", false); final FileBasedConfig cfg = src.getConfig();
src.getConfig().save(); cfg.setBoolean("http", null, "uploadpack", false);
cfg.save();
Repository dst = createBareRepository(); Repository dst = createBareRepository();
Transport t = Transport.open(dst, smartAuthNoneURI); Transport t = Transport.open(dst, smartAuthNoneURI);

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java

@ -47,9 +47,9 @@ import java.net.URISyntaxException;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTag; import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RefSpec;
@ -66,11 +66,12 @@ public class FetchCommandTest extends RepositoryTestCase {
Git git2 = new Git(db2); Git git2 = new Git(db2);
// setup the first repository to fetch from the second repository // setup the first repository to fetch from the second repository
final Config config = db.getConfig(); final StoredConfig config = db.getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "test"); RemoteConfig remoteConfig = new RemoteConfig(config, "test");
URIish uri = new URIish(db2.getDirectory().toURI().toURL()); URIish uri = new URIish(db2.getDirectory().toURI().toURL());
remoteConfig.addURI(uri); remoteConfig.addURI(uri);
remoteConfig.update(config); remoteConfig.update(config);
config.save();
// create some refs via commits and tag // create some refs via commits and tag
RevCommit commit = git2.commit().setMessage("initial commit").call(); RevCommit commit = git2.commit().setMessage("initial commit").call();

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java

@ -199,8 +199,8 @@ public class PullCommandTest extends RepositoryTestCase {
.getPath())); .getPath()));
config.addFetchRefSpec(new RefSpec( config.addFetchRefSpec(new RefSpec(
"+refs/heads/*:refs/remotes/origin/*")); "+refs/heads/*:refs/remotes/origin/*"));
targetConfig.save();
config.update(targetConfig); config.update(targetConfig);
targetConfig.save();
targetFile = new File(dbTarget.getWorkTree(), "SomeFile.txt"); targetFile = new File(dbTarget.getWorkTree(), "SomeFile.txt");
writeToFile(targetFile, "Hello world"); writeToFile(targetFile, "Hello world");

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java

@ -48,9 +48,9 @@ import java.net.URISyntaxException;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTag; import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RefSpec;
@ -66,11 +66,12 @@ public class PushCommandTest extends RepositoryTestCase {
Repository db2 = createWorkRepository(); Repository db2 = createWorkRepository();
// setup the first repository // setup the first repository
final Config config = db.getConfig(); final StoredConfig config = db.getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "test"); RemoteConfig remoteConfig = new RemoteConfig(config, "test");
URIish uri = new URIish(db2.getDirectory().toURI().toURL()); URIish uri = new URIish(db2.getDirectory().toURI().toURL());
remoteConfig.addURI(uri); remoteConfig.addURI(uri);
remoteConfig.update(config); remoteConfig.update(config);
config.save();
Git git1 = new Git(db); Git git1 = new Git(db);
// create some refs via commits and tag // create some refs via commits and tag

16
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java

@ -47,6 +47,8 @@ package org.eclipse.jgit.lib;
import java.io.IOException; import java.io.IOException;
import org.eclipse.jgit.storage.file.FileBasedConfig;
public class ReflogConfigTest extends RepositoryTestCase { public class ReflogConfigTest extends RepositoryTestCase {
public void testlogAllRefUpdates() throws Exception { public void testlogAllRefUpdates() throws Exception {
long commitTime = 1154236443000L; long commitTime = 1154236443000L;
@ -55,7 +57,9 @@ public class ReflogConfigTest extends RepositoryTestCase {
// check that there are no entries in the reflog and turn off writing // check that there are no entries in the reflog and turn off writing
// reflogs // reflogs
assertEquals(0, db.getReflogReader(Constants.HEAD).getReverseEntries().size()); assertEquals(0, db.getReflogReader(Constants.HEAD).getReverseEntries().size());
db.getConfig().setBoolean("core", null, "logallrefupdates", false); final FileBasedConfig cfg = db.getConfig();
cfg.setBoolean("core", null, "logallrefupdates", false);
cfg.save();
// do one commit and check that reflog size is 0: no reflogs should be // do one commit and check that reflog size is 0: no reflogs should be
// written // written
@ -69,8 +73,9 @@ public class ReflogConfigTest extends RepositoryTestCase {
db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 0); db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 0);
// set the logAllRefUpdates parameter to true and check it // set the logAllRefUpdates parameter to true and check it
db.getConfig().setBoolean("core", null, "logallrefupdates", true); cfg.setBoolean("core", null, "logallrefupdates", true);
assertTrue(db.getConfig().get(CoreConfig.KEY).isLogAllRefUpdates()); cfg.save();
assertTrue(cfg.get(CoreConfig.KEY).isLogAllRefUpdates());
// do one commit and check that reflog size is increased to 1 // do one commit and check that reflog size is increased to 1
addFileToTree(t, "i-am-another-file", "and this is other data in me\n"); addFileToTree(t, "i-am-another-file", "and this is other data in me\n");
@ -82,8 +87,9 @@ public class ReflogConfigTest extends RepositoryTestCase {
db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 1); db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 1);
// set the logAllRefUpdates parameter to false and check it // set the logAllRefUpdates parameter to false and check it
db.getConfig().setBoolean("core", null, "logallrefupdates", false); cfg.setBoolean("core", null, "logallrefupdates", false);
assertFalse(db.getConfig().get(CoreConfig.KEY).isLogAllRefUpdates()); cfg.save();
assertFalse(cfg.get(CoreConfig.KEY).isLogAllRefUpdates());
// do one commit and check that reflog size is 2 // do one commit and check that reflog size is 2
addFileToTree(t, "i-am-anotheranother-file", addFileToTree(t, "i-am-anotheranother-file",

Loading…
Cancel
Save