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:com.diffplug.gradle.spotless.GitAttributesLineEndingPolicy.java
License:Apache License
public static GitAttributesLineEndingPolicy create(File rootFolder) { return Errors.rethrow().get(() -> { FileRepositoryBuilder builder = new FileRepositoryBuilder(); builder.findGitDir(rootFolder);//w ww . j a v a 2 s . c o m if (builder.getGitDir() != null) { // we found a repository, so we can grab all the values we need from it Repository repo = builder.build(); AttributesNodeProvider nodeProvider = repo.createAttributesNodeProvider(); Function<AttributesNode, List<AttributesRule>> getRules = node -> node == null ? Collections.emptyList() : node.getRules(); return new GitAttributesLineEndingPolicy(repo.getConfig(), getRules.apply(nodeProvider.getInfoAttributesNode()), repo.getWorkTree(), getRules.apply(nodeProvider.getGlobalAttributesNode())); } else { // there's no repo, so it takes some work to grab the system-wide values Config systemConfig = SystemReader.getInstance().openSystemConfig(null, FS.DETECTED); Config userConfig = SystemReader.getInstance().openUserConfig(systemConfig, FS.DETECTED); if (userConfig == null) { userConfig = new Config(); } List<AttributesRule> globalRules = Collections.emptyList(); // copy-pasted from org.eclipse.jgit.lib.CoreConfig String globalAttributesPath = userConfig.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_ATTRIBUTESFILE); // copy-pasted from org.eclipse.jgit.internal.storage.file.GlobalAttributesNode if (globalAttributesPath != null) { FS fs = FS.detect(); File attributesFile; if (globalAttributesPath.startsWith("~/")) { //$NON-NLS-1$ attributesFile = fs.resolve(fs.userHome(), globalAttributesPath.substring(2)); } else { attributesFile = fs.resolve(null, globalAttributesPath); } globalRules = parseRules(attributesFile); } return new GitAttributesLineEndingPolicy(userConfig, // no git info file Collections.emptyList(), null, globalRules); } }); }
From source file:com.diffplug.gradle.spotless.GitAttributesLineEndingPolicy.java
License:Apache License
private GitAttributesLineEndingPolicy(Config config, List<AttributesRule> infoRules, File workTree, List<AttributesRule> globalRules) { this.infoRules = Objects.requireNonNull(infoRules); this.workTree = workTree; this.globalRules = Objects.requireNonNull(globalRules); this.defaultEnding = fromEol(config.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_EOL, EOL.NATIVE)).str(); }
From source file:com.google.gerrit.server.git.LocalDiskRepositoryManager.java
License:Apache License
private Repository createRepository(Path path, Project.NameKey name) throws RepositoryNotFoundException, RepositoryCaseMismatchException { if (isUnreasonableName(name)) { throw new RepositoryNotFoundException("Invalid name: " + name); }//ww w . j a va2s . co m File dir = FileKey.resolve(path.resolve(name.get()).toFile(), FS.DETECTED); FileKey loc; if (dir != null) { // Already exists on disk, use the repository we found. // loc = FileKey.exact(dir, FS.DETECTED); if (!names.contains(name)) { throw new RepositoryCaseMismatchException(name); } } else { // It doesn't exist under any of the standard permutations // of the repository name, so prefer the standard bare name. // String n = name.get() + Constants.DOT_GIT_EXT; loc = FileKey.exact(path.resolve(n).toFile(), FS.DETECTED); } try { Repository db = RepositoryCache.open(loc, false); db.create(true /* bare */); StoredConfig config = db.getConfig(); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES, true); config.save(); // JGit only writes to the reflog for refs/meta/config if the log file // already exists. // File metaConfigLog = new File(db.getDirectory(), "logs/" + RefNames.REFS_CONFIG); if (!metaConfigLog.getParentFile().mkdirs() || !metaConfigLog.createNewFile()) { log.error(String.format("Failed to create ref log for %s in repository %s", RefNames.REFS_CONFIG, name)); } onCreateProject(name); return db; } catch (IOException e1) { final RepositoryNotFoundException e2; e2 = new RepositoryNotFoundException("Cannot create repository " + name); e2.initCause(e1); throw e2; } }
From source file:com.microsoft.gittf.core.config.GitTFConfiguration.java
License:Open Source License
/** * Saves this configuration to the given git repository's configuration. * // w w w . j ava2 s .co 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:ezbake.deployer.publishers.openShift.RhcApplication.java
License:Apache License
/** * Sets the git repository object. Probably not useful but here for Java Bean completeness * * @param gitRepo - git repository to set it to *///from w w w.j ava 2 s . co m public void setGitRepo(Git gitRepo) throws DeploymentException { this.gitRepo = gitRepo; try { StoredConfig config = gitRepo.getRepository().getConfig(); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, true); config.save(); } catch (IOException e) { log.error("There was an error saving the git configuration to disk", e); throw new DeploymentException("Could not save git configuration: " + e.getMessage()); } }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitServerUtil.java
License:Apache License
private static boolean hasValidFormatVersion(Config config) { final String repositoryFormatVersion = config.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION); return "0".equals(repositoryFormatVersion); }
From source file:org.archicontribs.modelrepository.grafico.GraficoUtils.java
License:Open Source License
/** * Clone a model// w w w. jav a 2 s. c o m * @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.egit.ui.view.repositories.GitRepositoriesViewTestBase.java
License:Open Source License
protected static File createProjectAndCommitToRepository() throws Exception { File gitDir = new File(new File(getTestDirectory(), REPO1), Constants.DOT_GIT); gitDir.mkdir();// w ww.j a v a 2s.co m Repository myRepository = lookupRepository(gitDir); myRepository.create(); // TODO Bug: for some reason, this seems to be required myRepository.getConfig().setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, "0"); myRepository.getConfig().save(); // we need to commit into master first IProject firstProject = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1); if (firstProject.exists()) firstProject.delete(true, null); IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(PROJ1); desc.setLocation(new Path(new File(myRepository.getWorkTree(), PROJ1).getPath())); firstProject.create(desc, null); firstProject.open(null); IFolder folder = firstProject.getFolder(FOLDER); folder.create(false, true, null); IFile textFile = folder.getFile(FILE1); textFile.create(new ByteArrayInputStream("Hello, world".getBytes(firstProject.getDefaultCharset())), false, null); IFile textFile2 = folder.getFile(FILE2); textFile2.create(new ByteArrayInputStream("Some more content".getBytes(firstProject.getDefaultCharset())), false, null); new ConnectProviderOperation(firstProject, gitDir).execute(null); IProject secondPoject = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ2); if (secondPoject.exists()) secondPoject.delete(true, null); desc = ResourcesPlugin.getWorkspace().newProjectDescription(PROJ2); desc.setLocation(new Path(new File(myRepository.getWorkTree(), PROJ2).getPath())); secondPoject.create(desc, null); secondPoject.open(null); IFolder secondfolder = secondPoject.getFolder(FOLDER); secondfolder.create(false, true, null); IFile secondtextFile = secondfolder.getFile(FILE1); secondtextFile.create(new ByteArrayInputStream("Hello, world".getBytes(firstProject.getDefaultCharset())), false, null); IFile secondtextFile2 = secondfolder.getFile(FILE2); secondtextFile2.create( new ByteArrayInputStream("Some more content".getBytes(firstProject.getDefaultCharset())), false, null); new ConnectProviderOperation(secondPoject, gitDir).execute(null); IFile[] commitables = new IFile[] { firstProject.getFile(".project"), textFile, textFile2, secondtextFile, secondtextFile2 }; ArrayList<IFile> untracked = new ArrayList<IFile>(); untracked.addAll(Arrays.asList(commitables)); // commit to stable CommitOperation op = new CommitOperation(commitables, new ArrayList<IFile>(), untracked, "Test Author <test.author@test.com>", "Test Committer <test.commiter@test.com>", "Initial commit"); op.execute(null); // now create a stable branch (from master) createStableBranch(myRepository); // and check in some stuff into master again touchAndSubmit(null); return gitDir; }
From source file:org.eclipse.egit.ui.view.repositories.GitRepositoriesViewTestBase.java
License:Open Source License
protected static File createRemoteRepository(File repositoryDir) throws Exception { Repository myRepository = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache() .lookupRepository(repositoryDir); File gitDir = new File(getTestDirectory(), REPO2); Repository myRemoteRepository = lookupRepository(gitDir); myRemoteRepository.create();//from w ww.j a v a2s .c o m createStableBranch(myRepository); // now we configure the push destination myRepository.getConfig().setString("remote", "push", "pushurl", "file:///" + myRemoteRepository.getDirectory().getPath()); myRepository.getConfig().setString("remote", "push", "push", "+refs/heads/*:refs/heads/*"); // TODO Bug: for some reason, this seems to be required myRepository.getConfig().setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, "0"); myRepository.getConfig().save(); // and push PushConfiguredRemoteAction pa = new PushConfiguredRemoteAction(myRepository, "push"); pa.run(null, false); TestUtil.joinJobs(JobFamilies.PUSH); try { // delete the stable branch again RefUpdate op = myRepository.updateRef("refs/heads/stable"); op.setRefLogMessage("branch deleted", //$NON-NLS-1$ false); // we set the force update in order // to avoid having this rejected // due to minor issues op.setForceUpdate(true); op.delete(); } catch (IOException ioe) { throw new InvocationTargetException(ioe); } return myRemoteRepository.getDirectory(); }
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();/*from w w w . j ava2 s . c o m*/ 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; }