List of usage examples for org.eclipse.jgit.lib Config Config
public Config()
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);/* www .j av a 2 s.c om*/ 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.ericsson.gerrit.plugins.highavailability.ConfigurationTest.java
License:Apache License
@Before public void setUp() throws IOException { globalPluginConfig = new Config(); when(pluginConfigFactoryMock.getGlobalPluginConfig(PLUGIN_NAME)).thenReturn(globalPluginConfig); sitePaths = new SitePaths(SITE_PATH); }
From source file:com.ericsson.gerrit.plugins.highavailability.peers.jgroups.MyUrlProviderTest.java
License:Apache License
@Before public void setUp() { gerritServerConfig = new Config(); }
From source file:com.gitblit.wicket.pages.NewRepositoryPage.java
License:Apache License
/** * Prepare the initial commit for the repository. * * @param repository//from w w w .j av a 2 s . c om * @param addReadme * @param gitignore * @param addGitFlow * @return true if an initial commit was created */ protected boolean initialCommit(RepositoryModel repository, boolean addReadme, String gitignore, boolean addGitFlow) { boolean initialCommit = addReadme || !StringUtils.isEmpty(gitignore) || addGitFlow; if (!initialCommit) { return false; } // build an initial commit boolean success = false; Repository db = app().repositories().getRepository(repositoryModel.name); ObjectInserter odi = db.newObjectInserter(); try { UserModel user = GitBlitWebSession.get().getUser(); String email = Optional.fromNullable(user.emailAddress).or(user.username + "@" + "gitblit"); PersonIdent author = new PersonIdent(user.getDisplayName(), email); DirCache newIndex = DirCache.newInCore(); DirCacheBuilder indexBuilder = newIndex.builder(); if (addReadme) { // insert a README String title = StringUtils.stripDotGit(StringUtils.getLastPathElement(repositoryModel.name)); String description = repositoryModel.description == null ? "" : repositoryModel.description; String readme = String.format("## %s\n\n%s\n\n", title, description); byte[] bytes = readme.getBytes(Constants.ENCODING); DirCacheEntry entry = new DirCacheEntry("README.md"); entry.setLength(bytes.length); entry.setLastModified(System.currentTimeMillis()); entry.setFileMode(FileMode.REGULAR_FILE); entry.setObjectId(odi.insert(org.eclipse.jgit.lib.Constants.OBJ_BLOB, bytes)); indexBuilder.add(entry); } if (!StringUtils.isEmpty(gitignore)) { // insert a .gitignore file File dir = app().runtime().getFileOrFolder(Keys.git.gitignoreFolder, "${baseFolder}/gitignore"); File file = new File(dir, gitignore + ".gitignore"); if (file.exists() && file.length() > 0) { byte[] bytes = FileUtils.readContent(file); if (!ArrayUtils.isEmpty(bytes)) { DirCacheEntry entry = new DirCacheEntry(".gitignore"); entry.setLength(bytes.length); entry.setLastModified(System.currentTimeMillis()); entry.setFileMode(FileMode.REGULAR_FILE); entry.setObjectId(odi.insert(org.eclipse.jgit.lib.Constants.OBJ_BLOB, bytes)); indexBuilder.add(entry); } } } if (addGitFlow) { // insert a .gitflow file Config config = new Config(); config.setString("gitflow", null, "masterBranch", Constants.MASTER); config.setString("gitflow", null, "developBranch", Constants.DEVELOP); config.setString("gitflow", null, "featureBranchPrefix", "feature/"); config.setString("gitflow", null, "releaseBranchPrefix", "release/"); config.setString("gitflow", null, "hotfixBranchPrefix", "hotfix/"); config.setString("gitflow", null, "supportBranchPrefix", "support/"); config.setString("gitflow", null, "versionTagPrefix", ""); byte[] bytes = config.toText().getBytes(Constants.ENCODING); DirCacheEntry entry = new DirCacheEntry(".gitflow"); entry.setLength(bytes.length); entry.setLastModified(System.currentTimeMillis()); entry.setFileMode(FileMode.REGULAR_FILE); entry.setObjectId(odi.insert(org.eclipse.jgit.lib.Constants.OBJ_BLOB, bytes)); indexBuilder.add(entry); } indexBuilder.finish(); if (newIndex.getEntryCount() == 0) { // nothing to commit return false; } ObjectId treeId = newIndex.writeTree(odi); // Create a commit object CommitBuilder commit = new CommitBuilder(); commit.setAuthor(author); commit.setCommitter(author); commit.setEncoding(Constants.ENCODING); commit.setMessage("Initial commit"); commit.setTreeId(treeId); // Insert the commit into the repository ObjectId commitId = odi.insert(commit); odi.flush(); // set the branch refs RevWalk revWalk = new RevWalk(db); try { // set the master branch RevCommit revCommit = revWalk.parseCommit(commitId); RefUpdate masterRef = db.updateRef(Constants.R_MASTER); masterRef.setNewObjectId(commitId); masterRef.setRefLogMessage("commit: " + revCommit.getShortMessage(), false); Result masterRC = masterRef.update(); switch (masterRC) { case NEW: success = true; break; default: success = false; } if (addGitFlow) { // set the develop branch for git-flow RefUpdate developRef = db.updateRef(Constants.R_DEVELOP); developRef.setNewObjectId(commitId); developRef.setRefLogMessage("commit: " + revCommit.getShortMessage(), false); Result developRC = developRef.update(); switch (developRC) { case NEW: success = true; break; default: success = false; } } } finally { revWalk.close(); } } catch (UnsupportedEncodingException e) { logger().error(null, e); } catch (IOException e) { logger().error(null, e); } finally { odi.close(); db.close(); } return success; }
From source file:com.google.gerrit.acceptance.AbstractDaemonTest.java
License:Apache License
protected static Config submitWholeTopicEnabledConfig() { Config cfg = new Config(); cfg.setBoolean("change", null, "submitWholeTopic", true); return cfg;//ww w . j ava 2 s .c om }
From source file:com.google.gerrit.acceptance.AbstractDaemonTest.java
License:Apache License
protected static Config allowDraftsDisabledConfig() { Config cfg = new Config(); cfg.setBoolean("change", null, "allowDrafts", false); return cfg;// w w w .j a v a 2 s . com }
From source file:com.google.gerrit.acceptance.api.accounts.AccountIT.java
License:Apache License
@ConfigSuite.Default public static Config enableSignedPushConfig() { Config cfg = new Config(); cfg.setBoolean("receive", null, "enableSignedPush", true); return cfg;/*from w w w . j av a 2 s . c o m*/ }
From source file:com.google.gerrit.acceptance.api.accounts.AgreementsIT.java
License:Apache License
@ConfigSuite.Config public static Config enableAgreementsConfig() { Config cfg = new Config(); cfg.setBoolean("auth", null, "contributorAgreements", true); return cfg;// w w w . ja v a 2 s . c om }
From source file:com.google.gerrit.acceptance.git.AbstractSubmoduleSubscription.java
License:Apache License
protected void createSubscription(TestRepository<?> repo, String branch, String subscribeToRepo, String subscribeToBranch) throws Exception { Config config = new Config(); prepareSubscriptionConfigEntry(config, subscribeToRepo, subscribeToBranch); pushSubscriptionConfig(repo, branch, config); }
From source file:com.google.gerrit.acceptance.git.SubmoduleSectionParserIT.java
License:Apache License
@Test public void testFollowMasterBranch() throws Exception { Project.NameKey p = createProject("a"); Config cfg = new Config(); cfg.fromText("" + "[submodule \"a\"]\n" + "path = localpath-to-a\n" + "url = ssh://localhost/" + p.get() + "\n" + "branch = master\n"); Branch.NameKey targetBranch = new Branch.NameKey(new Project.NameKey("project"), "master"); Set<SubmoduleSubscription> res = new SubmoduleSectionParser(cfg, THIS_SERVER, targetBranch) .parseAllSections();/*from ww w . j av a 2 s. c om*/ Set<SubmoduleSubscription> expected = Sets.newHashSet( new SubmoduleSubscription(targetBranch, new Branch.NameKey(p, "master"), "localpath-to-a")); assertThat(res).containsExactlyElementsIn(expected); }