List of usage examples for org.eclipse.jgit.lib ConfigConstants CONFIG_CORE_SECTION
String CONFIG_CORE_SECTION
To view the source code for org.eclipse.jgit.lib ConfigConstants CONFIG_CORE_SECTION.
Click Source Link
From source file:org.eclipse.orion.server.git.servlets.GitCloneHandlerV1.java
License:Open Source License
static void doConfigureClone(Git git, String user) throws IOException, CoreException { StoredConfig config = git.getRepository().getConfig(); IOrionUserProfileNode userNode = UserServiceHelper.getDefault().getUserProfileService() .getUserProfileNode(user, true).getUserProfileNode(IOrionUserProfileConstants.GENERAL_PROFILE_PART); if (userNode.get(GitConstants.KEY_NAME, null) != null) config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME, userNode.get(GitConstants.KEY_NAME, null)); if (userNode.get(GitConstants.KEY_MAIL, null) != null) config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL, userNode.get(GitConstants.KEY_MAIL, null)); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false); config.save();// w w w . j a v a 2s . c o m }
From source file:org.eclipse.orion.server.tests.servlets.git.GitResetTest.java
License:Open Source License
@Test @Ignore("see bug 339397") public void testResetAutocrlfTrue() throws Exception { // "git config core.autocrlf true" Git git = new Git(db); StoredConfig config = git.getRepository().getConfig(); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, Boolean.TRUE);/*ww w .j av a2 s . c o m*/ config.save(); URI workspaceLocation = createWorkspace(getMethodName()); String projectName = getMethodName(); JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString()); String projectId = project.getString(ProtocolConstants.KEY_ID); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX); String gitStatusUri = gitSection.getString(GitConstants.KEY_STATUS); String gitCommitUri = gitSection.getString(GitConstants.KEY_COMMIT); // CRLF // TODO: don't create URIs out of thin air WebRequest request = getPutFileRequest(projectId + "/test.txt", "f" + "\r\n" + "older"); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // "git add {path}" // TODO: don't create URIs out of thin air request = GitAddTest.getPutGitIndexRequest(gitIndexUri + "test.txt"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // commit request = GitCommitTest.getPostGitCommitRequest(gitCommitUri, "added new line - crlf", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // assert there is nothing to commit request = GitStatusTest.getGetGitStatusRequest(gitStatusUri); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject statusResponse = new JSONObject(response.getText()); GitStatusTest.assertStatusClean(statusResponse); // create new file String fileName = "new.txt"; request = getPostFilesRequest(projectId + "/", getNewFileJSON(fileName).toString(), fileName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); JSONObject file = new JSONObject(response.getText()); String location = file.optString(ProtocolConstants.KEY_LOCATION, null); assertNotNull(location); // LF request = getPutFileRequest(location, "i'm" + "\n" + "new"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // "git add ." request = GitAddTest.getPutGitIndexRequest(gitIndexUri /* stage all */); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // reset request = getPostGitIndexRequest(gitIndexUri /* reset all */, ResetType.MIXED); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); request = GitStatusTest.getGetGitStatusRequest(gitStatusUri); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); statusResponse = new JSONObject(response.getText()); JSONArray statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_ADDED); assertEquals(0, statusArray.length()); statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_CHANGED); assertEquals(0, statusArray.length()); statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_MISSING); assertEquals(0, statusArray.length()); statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_MODIFIED); assertEquals(0, statusArray.length()); statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_REMOVED); assertEquals(0, statusArray.length()); statusArray = statusResponse.getJSONArray(GitConstants.KEY_STATUS_UNTRACKED); assertEquals(1, statusArray.length()); }
From source file:org.sonatype.m2e.egit.internal.EgitScmHandler.java
License:Open Source License
protected void fixAutoCRLF(File gitDirectory) throws IOException { // jgit does not have support for core.autocrlf but it sets the core.autocrlf=false in the local git // repository config (https://bugs.eclipse.org/bugs/show_bug.cgi?id=301775). // We need to unset it. FileRepository localRepository = new FileRepository(gitDirectory); try {//from www. j a v a2 s . c o m FileBasedConfig localConfig = localRepository.getConfig(); localConfig.unset(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF); localConfig.save(); } finally { localRepository.close(); } }
From source file:org.z2env.impl.helper.GitTools.java
License:Apache License
/** * Clones the given remote repository into the given destination folder. The method clones all branches but doesn't perform a checkout. * // www .ja v a2 s.co m * @param remoteUri URI of the remote repository * @param destFolder local destination folder * @param credentials user credentials * @return the cloned repository * @throws IOException if something went wrong */ public static Repository cloneRepository(URIish remoteUri, File destFolder, CredentialsProvider credentials, int timeout) throws IOException { // workaround for http://redmine.z2-environment.net/issues/902: // split clone into its piece in order to get the chance to set "core.autocrlf" Git gitResult; try { gitResult = Git.init().setBare(false).setDirectory(destFolder).call(); } catch (Exception e) { throw new IOException("Failed to initialize a new Git repository at " + destFolder.getAbsolutePath(), e); } Repository repo = gitResult.getRepository(); // setting "core.autocrlf=false" helps to solve http://redmine.z2-environment.net/issues/902 StoredConfig config = repo.getConfig(); config.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, String.valueOf(false)); // add origin - clone all branches RemoteConfig remoteCfg = null; try { remoteCfg = new RemoteConfig(config, "origin"); } catch (URISyntaxException e) { throw new IOException("Failed to configure origin repository", e); } remoteCfg.addURI(remoteUri); remoteCfg.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*")); remoteCfg.update(config); config.save(); // fetch all branches from origin try { gitResult.fetch().setRemote("origin").setCredentialsProvider(credentials).setTimeout(timeout).call(); } catch (Exception e) { throw new IOException("Failed to fetch from origin!", e); } return repo; }