List of usage examples for org.eclipse.jgit.lib ConfigConstants CONFIG_KEY_AUTOCRLF
String CONFIG_KEY_AUTOCRLF
To view the source code for org.eclipse.jgit.lib ConfigConstants CONFIG_KEY_AUTOCRLF.
Click Source Link
From source file:com.microsoft.gittf.core.config.GitTFConfiguration.java
License:Open Source License
/** * Saves this configuration to the given git repository's configuration. * //from www . j a v a 2s . c o m * @param repository * The {@link Repository} to save this configuration to (must not be * <code>null</code>) * @return <code>true</code> if the configuration was saved successfully */ public boolean saveTo(final Repository repository) { Check.notNull(repository, "repository"); //$NON-NLS-1$ repository.getConfig().setString(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.SERVER_SUBSECTION, ConfigurationConstants.SERVER_COLLECTION_URI, serverURI.toASCIIString()); repository.getConfig().setString(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.SERVER_SUBSECTION, ConfigurationConstants.SERVER_PATH, tfsPath); if (isLocallyDefined(ConfigurationConstants.DEPTH)) { repository.getConfig().setInt(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.DEPTH, deep ? Integer.MAX_VALUE : 1); } if (isLocallyDefined(ConfigurationConstants.FILE_FORMAT_VERSION)) { repository.getConfig().setInt(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.FILE_FORMAT_VERSION, GitTFConstants.GIT_TF_CURRENT_FORMAT_VERSION); } if (isLocallyDefined(ConfigurationConstants.TAG)) { repository.getConfig().setBoolean(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.TAG, tag); } if (isLocallyDefined(ConfigurationConstants.INCLUDE_METADATA)) { repository.getConfig().setBoolean(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.INCLUDE_METADATA, includeMetaData); } if (isLocallyDefined(ConfigurationConstants.KEEP_AUTHOR)) { repository.getConfig().setBoolean(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.KEEP_AUTHOR, keepAuthor); } if (isLocallyDefined(ConfigurationConstants.USER_MAP)) { if (!StringUtil.isNullOrEmpty(userMap)) { repository.getConfig().setString(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.USER_MAP, userMap); } else { repository.getConfig().unset(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.USER_MAP); } } if (isLocallyDefined(ConfigurationConstants.GATED_BUILD_DEFINITION) && !StringUtil.isNullOrEmpty(buildDefinition)) { repository.getConfig().setString(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.SERVER_SUBSECTION, ConfigurationConstants.GATED_BUILD_DEFINITION, buildDefinition); } if (isLocallyDefined(ConfigurationConstants.USERNAME)) { repository.getConfig().setString(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.SERVER_SUBSECTION, ConfigurationConstants.USERNAME, username); } if (isLocallyDefined(ConfigurationConstants.PASSWORD)) { repository.getConfig().setString(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.SERVER_SUBSECTION, ConfigurationConstants.PASSWORD, password); } if (isLocallyDefined(ConfigurationConstants.TEMP_DIRECTORY) && !StringUtil.isNullOrEmpty(tempDirectory)) { repository.getConfig().setString(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.TEMP_DIRECTORY, tempDirectory); } repository.getConfig().setEnum(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.FALSE); try { repository.getConfig().save(); } catch (IOException e) { log.error("Could not save server configuration to repository", e); //$NON-NLS-1$ return false; } return true; }
From source file:org.archicontribs.modelrepository.grafico.GraficoUtils.java
License:Open Source License
/** * Clone a model/* w w w.j a v a 2s . c om*/ * @param localGitFolder * @param repoURL * @param userName * @param userPassword * @param monitor * @throws GitAPIException * @throws IOException */ public static void cloneModel(File localGitFolder, String repoURL, String userName, String userPassword, ProgressMonitor monitor) throws GitAPIException, IOException { CloneCommand cloneCommand = Git.cloneRepository(); cloneCommand.setDirectory(localGitFolder); cloneCommand.setURI(repoURL); cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, userPassword)); cloneCommand.setProgressMonitor(monitor); try (Git git = cloneCommand.call()) { // Use the same line endings StoredConfig config = git.getRepository().getConfig(); config.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "true"); //$NON-NLS-1$ config.save(); } }
From source file:org.eclipse.oomph.setup.git.impl.GitCloneTaskImpl.java
License:Open Source License
private static boolean configureLineEndingConversion(SetupTaskContext context, StoredConfig config) throws Exception { OS os = context.getOS();/*w ww . j a va 2 s. com*/ if (os.isLineEndingConversionNeeded()) { if (context.isPerforming()) { context.log("Setting " + ConfigConstants.CONFIG_KEY_AUTOCRLF + " = true"); } config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.TRUE); return true; } return false; }
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);// w ww . ja v 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 {//w w w .j ava 2s . c om 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. * /*from w w w. ja v a2 s. c o 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; }