SystemReaderInstaller: Return a new instance from getSystemConfig
This is the only way to respect the passed-in parent config, which may be different on each invocation. Additionally, returning a new instance matches the behavior of the default system reader, which downstream callers may be depending on. Change-Id: If95ccf4e97d4b969cdba7a6e85e613e9acc3ff0d
This commit is contained in:
		@@ -47,8 +47,6 @@ public class SystemReaderInstaller implements LifecycleListener {
 | 
			
		||||
  private SystemReader customReader() {
 | 
			
		||||
    SystemReader current = SystemReader.getInstance();
 | 
			
		||||
 | 
			
		||||
    FileBasedConfig jgitConfig = new FileBasedConfig(site.jgit_config.toFile(), FS.DETECTED);
 | 
			
		||||
 | 
			
		||||
    return new SystemReader() {
 | 
			
		||||
      @Override
 | 
			
		||||
      public String getHostname() {
 | 
			
		||||
@@ -72,7 +70,7 @@ public class SystemReaderInstaller implements LifecycleListener {
 | 
			
		||||
 | 
			
		||||
      @Override
 | 
			
		||||
      public FileBasedConfig openSystemConfig(Config parent, FS fs) {
 | 
			
		||||
        return jgitConfig;
 | 
			
		||||
        return new FileBasedConfig(parent, site.jgit_config.toFile(), FS.DETECTED);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,11 @@ import java.nio.charset.StandardCharsets;
 | 
			
		||||
import java.nio.file.Files;
 | 
			
		||||
import java.nio.file.Path;
 | 
			
		||||
import org.eclipse.jgit.internal.storage.file.FileRepository;
 | 
			
		||||
import org.eclipse.jgit.lib.Config;
 | 
			
		||||
import org.eclipse.jgit.lib.Repository;
 | 
			
		||||
import org.eclipse.jgit.storage.file.FileBasedConfig;
 | 
			
		||||
import org.eclipse.jgit.util.FS;
 | 
			
		||||
import org.eclipse.jgit.util.SystemReader;
 | 
			
		||||
import org.junit.Before;
 | 
			
		||||
import org.junit.Rule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
@@ -52,4 +56,29 @@ public class JGitConfigTest {
 | 
			
		||||
      assertThat(repo.getConfig().getString("core", null, "trustFolderStat")).isEqualTo("false");
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void openSystemConfigRespectsParent() throws Exception {
 | 
			
		||||
    Config parent = new Config();
 | 
			
		||||
    parent.setString("foo", null, "bar", "value");
 | 
			
		||||
    FileBasedConfig system = SystemReader.getInstance().openSystemConfig(parent, FS.DETECTED);
 | 
			
		||||
    system.load();
 | 
			
		||||
    assertThat(system.getString("core", null, "trustFolderStat")).isEqualTo("false");
 | 
			
		||||
    assertThat(system.getString("foo", null, "bar")).isEqualTo("value");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void openSystemConfigReturnsDifferentInstances() throws Exception {
 | 
			
		||||
    FileBasedConfig system1 = SystemReader.getInstance().openSystemConfig(null, FS.DETECTED);
 | 
			
		||||
    system1.load();
 | 
			
		||||
    assertThat(system1.getString("core", null, "trustFolderStat")).isEqualTo("false");
 | 
			
		||||
 | 
			
		||||
    FileBasedConfig system2 = SystemReader.getInstance().openSystemConfig(null, FS.DETECTED);
 | 
			
		||||
    system2.load();
 | 
			
		||||
    assertThat(system2.getString("core", null, "trustFolderStat")).isEqualTo("false");
 | 
			
		||||
 | 
			
		||||
    system1.setString("core", null, "trustFolderStat", "true");
 | 
			
		||||
    assertThat(system1.getString("core", null, "trustFolderStat")).isEqualTo("true");
 | 
			
		||||
    assertThat(system2.getString("core", null, "trustFolderStat")).isEqualTo("false");
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user