org.eclipse.jgit.errors.ConfigInvalidException Java Examples

The following examples show how to use org.eclipse.jgit.errors.ConfigInvalidException. 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: LegacyCompatibleGitAPIImplTest.java    From git-client-plugin with MIT License 6 votes vote down vote up
@Test
@Deprecated
public void testCloneRemoteConfig() throws URISyntaxException, InterruptedException, IOException, ConfigInvalidException {
    if (gitImpl.equals("jgit")) {
        return;
    }
    Config config = new Config();
    /* Use local git-client-plugin repository as source for clone test */
    String remoteName = "localCopy";
    String localRepoPath = (new File(".")).getCanonicalPath().replace("\\", "/");
    String configText = "[remote \"" + remoteName + "\"]\n"
            + "url = " + localRepoPath + "\n"
            + "fetch = +refs/heads/*:refs/remotes/" + remoteName + "/*\n";
    config.fromText(configText);
    RemoteConfig remoteConfig = new RemoteConfig(config, remoteName);
    List<URIish> list = remoteConfig.getURIs();
    git.clone(remoteConfig);
    File[] files = git.workspace.listFiles();
    assertEquals(files.length + "files in " + Arrays.toString(files), 1, files.length);
    assertEquals("Wrong file name", ".git", files[0].getName());
}
 
Example #3
Source File: RepositoryInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void refresh () {
    try {
        if (config.isOutdated()) {
            config.load();
        }
    } catch (IOException | ConfigInvalidException ex) {
        LOG.log(Level.INFO, null, ex);
    }
}
 
Example #4
Source File: GitConfigHandlerV1.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
private boolean handleDelete(HttpServletRequest request, HttpServletResponse response, String path) throws CoreException, IOException, ServletException,
		ConfigInvalidException, URISyntaxException {
	Path p = new Path(path);
	if (p.segment(1).equals(Clone.RESOURCE) && p.segment(2).equals("file")) { //$NON-NLS-1$
		// expected path /gitapi/config/{key}/clone/file/{path}
		File gitDir = GitUtils.getGitDir(p.removeFirstSegments(2));
		if (gitDir == null)
			return statusHandler.handleRequest(request, response,
					new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, NLS.bind("No repository found under {0}", p.removeFirstSegments(2)),
							null));
		Repository db = null;
		URI cloneLocation = BaseToCloneConverter.getCloneLocation(getURI(request), BaseToCloneConverter.CONFIG_OPTION);
		try {
			db = FileRepositoryBuilder.create(gitDir);
			ConfigOption configOption = new ConfigOption(cloneLocation, db, GitUtils.decode(p.segment(0)));
			if (configOption.exists()) {
				String query = request.getParameter("index"); //$NON-NLS-1$
				if (query != null) {
					List<String> existing = new ArrayList<String>(Arrays.asList(configOption.getValue()));
					existing.remove(Integer.parseInt(query));
					save(configOption, existing);
				} else {
					delete(configOption);
				}
				response.setStatus(HttpServletResponse.SC_OK);
			} else {
				response.setStatus(HttpServletResponse.SC_NOT_FOUND);
			}
			return true;
		} catch (IllegalArgumentException e) {
			return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, e.getMessage(), e));
		} finally {
			if (db != null) {
				db.close();
			}
		}
	}
	return false;
}
 
Example #5
Source File: RepoRelativePath.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Tries to obtain repository name from the provided directory by reading git config in
 * {@code currendDir/.git/config}
 * <p>
 * Git clone folder name might be different from git repository name
 *
 * @return string with repo name or {@code null}
 */
private static String getRepoName(File currentDir) {
	if (currentDir == null) {
		return "NO_REPO";
	}
	File gitFolder = new File(currentDir, ".git");
	if (!gitFolder.isDirectory()) {
		if (LOGGER.isDebugEnabled())
			LOGGER.debug("No '.git' folder at " + currentDir.getAbsolutePath());
		return null;
	}

	File config = new File(gitFolder, "config");
	if (!config.isFile()) {
		if (LOGGER.isDebugEnabled())
			LOGGER.debug("No 'config' file at " + gitFolder.getAbsolutePath());
		return null;
	}
	try {
		String configStr = Files.asCharSource(config, Charset.defaultCharset()).read();
		Config cfg = new Config();

		cfg.fromText(configStr);
		String originURL = cfg.getString("remote", "origin", "url");
		if (originURL != null && !originURL.isEmpty()) {
			int lastSlash = originURL.lastIndexOf('/');
			String repoName = null;
			if (lastSlash >= 0) {
				repoName = originURL.substring(lastSlash + 1);
			} else {
				repoName = originURL;
			}
			if (repoName.endsWith(".git")) {
				repoName = repoName.substring(0, repoName.length() - 4);
			}
			return repoName;
		}
	} catch (ConfigInvalidException | IOException e) {
		LOGGER.warn("Cannot read git config at " + config.getAbsolutePath(), e);
	}

	return null;
}
 
Example #6
Source File: GitConfigHandlerV1.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
private boolean handlePost(HttpServletRequest request, HttpServletResponse response, String path) throws CoreException, IOException, JSONException,
		ServletException, URISyntaxException, ConfigInvalidException {
	Path p = new Path(path);
	if (p.segment(0).equals(Clone.RESOURCE) && p.segment(1).equals("file")) { //$NON-NLS-1$
		// expected path /gitapi/config/clone/file/{path}
		File gitDir = GitUtils.getGitDir(p.removeFirstSegments(1));
		if (gitDir == null)
			return statusHandler.handleRequest(request, response,
					new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, NLS.bind("No repository found under {0}", p.removeFirstSegments(1)),
							null));
		URI cloneLocation = BaseToCloneConverter.getCloneLocation(getURI(request), BaseToCloneConverter.CONFIG);
		JSONObject toPost = OrionServlet.readJSONRequest(request);
		String key = toPost.optString(GitConstants.KEY_CONFIG_ENTRY_KEY, null);
		if (key == null || key.isEmpty())
			return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST,
					"Config entry key must be provided", null));
		String value = toPost.optString(GitConstants.KEY_CONFIG_ENTRY_VALUE, null);
		if (value == null || value.isEmpty())
			return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST,
					"Config entry value must be provided", null));
		Repository db = null;
		try {
			db = FileRepositoryBuilder.create(gitDir);
			ConfigOption configOption = new ConfigOption(cloneLocation, db, key);
			boolean present = configOption.exists();
			ArrayList<String> valList = new ArrayList<String>();
			if (present) {
				String[] val = configOption.getValue();
				valList.addAll(Arrays.asList(val));
			}
			valList.add(value);
			save(configOption, valList);

			JSONObject result = configOption.toJSON();
			OrionServlet.writeJSONResponse(request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT);
			response.setHeader(ProtocolConstants.HEADER_LOCATION, result.getString(ProtocolConstants.KEY_LOCATION));
			response.setStatus(HttpServletResponse.SC_CREATED);
			return true;
		} catch (IllegalArgumentException e) {
			return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, e.getMessage(), e));
		} finally {
			if (db != null) {
				db.close();
			}
		}
	}
	return false;
}
 
Example #7
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;
}