org.eclipse.jgit.storage.file.FileBasedConfig Java Examples

The following examples show how to use org.eclipse.jgit.storage.file.FileBasedConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfigOption.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Retrieves local config without any base config.
 */
private FileBasedConfig getLocalConfig() throws IOException {
	// TODO: remove usage of internal type
	if (db instanceof FileRepository) {
		FileRepository fr = (FileRepository) db;
		FileBasedConfig config = new FileBasedConfig(fr.getConfig().getFile(), FS.detect());
		try {
			config.load();
		} catch (ConfigInvalidException e) {
			throw new IOException(e);
		}
		return config;
	} else {
		throw new IllegalArgumentException("Repository is not file based.");
	}
}
 
Example #2
Source File: JGitHelper.java    From go-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public void submoduleRemove(String folderName) {
    configRemoveSection(folderName);

    Repository repository = null;
    try {
        repository = getRepository(workingDir);

        StoredConfig gitSubmodulesConfig = new FileBasedConfig(null, new File(repository.getWorkTree(), Constants.DOT_GIT_MODULES), FS.DETECTED);
        gitSubmodulesConfig.unsetSection(ConfigConstants.CONFIG_SUBMODULE_SECTION, folderName);
        gitSubmodulesConfig.save();

        Git git = Git.wrap(repository);
        git.rm().setCached(true).addFilepattern(folderName).call();

        FileUtils.deleteQuietly(new File(workingDir, folderName));
    } catch (Exception e) {
        throw new RuntimeException("sub-module remove failed", e);
    } finally {
        if (repository != null) {
            repository.close();
        }
    }
}
 
Example #3
Source File: InitTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testInit () throws Exception {
    File repo2 = new File(workDir.getParentFile(), "other");
    GitClient client = GitRepository.getInstance(repo2).createClient();
    Field f = GitClient.class.getDeclaredField("gitRepository");
    f.setAccessible(true);
    JGitRepository jgitRepo = (JGitRepository) f.get(client);
    f = JGitRepository.class.getDeclaredField("repository");
    f.setAccessible(true);
    Repository repo = (Repository) f.get(jgitRepo);
    
    assertFalse(repo.getDirectory().exists());
    assertFalse(repo.getIndexFile().exists());
    assertNull(repo.getBranch());

    // test repository init
    client.init(NULL_PROGRESS_MONITOR);
    DirCache index = repo.readDirCache();
    assertEquals(0, index.getEntryCount());
    assertTrue(repo.getDirectory().exists());
    assertEquals("master", repo.getBranch());
    assertConfig(new FileBasedConfig(new File(repo.getDirectory(), "config"), repo.getFS()));

    // test failure when repository already exists
    try {
        client.init(NULL_PROGRESS_MONITOR);
        fail("Repository created twice");
    } catch (GitException ex) {
        assertTrue(ex.getMessage().contains("Git repository already exists"));
    }
}
 
Example #4
Source File: InitTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void assertConfig (FileBasedConfig config) throws Exception {
    config.load();
    // filemode
    assertEquals(isWindows() ? "false" : "true", config.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE));
    // bare
    assertEquals("false", config.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_BARE));
    // autocrlf
    assertEquals(null, config.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF));
}
 
Example #5
Source File: GitRepository.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
private static boolean exist(File repoDir) {
    try {
        final RepositoryBuilder repositoryBuilder = new RepositoryBuilder().setGitDir(repoDir);
        final org.eclipse.jgit.lib.Repository repository = repositoryBuilder.build();
        if (repository.getConfig() instanceof FileBasedConfig) {
            return ((FileBasedConfig) repository.getConfig()).getFile().exists();
        }
        return repository.getDirectory().exists();
    } catch (IOException e) {
        throw new StorageException("failed to check if repository exists at " + repoDir, e);
    }
}
 
Example #6
Source File: RepositoryInfo.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public NBGitConfig (File root) {
    this.config = new FileBasedConfig(new File(GitUtils.getGitFolderForRoot(root), NETBEANS_CONFIG_FILE), FS.DETECTED);
    saveTask = rp.create(new SaveTask());
}
 
Example #7
Source File: TransportCommand.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public FileBasedConfig openUserConfig (Config config, FS fs) {
    return instance.openUserConfig(config, fs);
}
 
Example #8
Source File: TransportCommand.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public FileBasedConfig openSystemConfig (Config config, FS fs) {
    return instance.openSystemConfig(config, fs);
}
 
Example #9
Source File: ConnectionTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public FileBasedConfig openUserConfig (Config config, FS fs) {
    return instance.openUserConfig(config, fs);
}
 
Example #10
Source File: ConnectionTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public FileBasedConfig openSystemConfig (Config config, FS fs) {
    return instance.openSystemConfig(config, fs);
}
 
Example #11
Source File: GitSubmoduleHandlerV1.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
private static StoredConfig getGitSubmodulesConfig( Repository repository ) throws IOException, ConfigInvalidException {
	File gitSubmodulesFile = new File( repository.getWorkTree(), DOT_GIT_MODULES );
	FileBasedConfig gitSubmodulesConfig = new FileBasedConfig( null, gitSubmodulesFile, FS.DETECTED );
	gitSubmodulesConfig.load();
	return gitSubmodulesConfig;
}
 
Example #12
Source File: ConfigOption.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public FileBasedConfig getConfig() {
	return config;
}