List of usage examples for org.eclipse.jgit.lib StoredConfig save
public abstract void save() throws IOException;
From source file:org.jboss.forge.rest.main.GitCommandCompletePostProcessor.java
License:Apache License
protected void configureBranch(Git git, String branch, String remote) { // lets update the merge config if (!Strings.isNullOrEmpty(branch)) { StoredConfig config = git.getRepository().getConfig(); if (io.hawt.util.Strings.isBlank(config.getString("branch", branch, "remote")) || io.hawt.util.Strings.isBlank(config.getString("branch", branch, "merge"))) { config.setString("branch", branch, "remote", remote); config.setString("branch", branch, "merge", "refs/heads/" + branch); try { config.save(); } catch (IOException e) { LOG.error("Failed to save the git configuration to " + git.getRepository().getDirectory() + " with branch " + branch + " on remote repo: " + remote + " due: " + e.getMessage() + ". This exception is ignored.", e); }//from w w w.jav a 2 s . c om } } }
From source file:org.jboss.tools.feedhenry.ui.internal.util.GitUtil.java
License:Open Source License
/** * Adds the remote config to given repository. * // ww w. java 2 s. com * @param remoteName * @param uri * @param repository * @throws URISyntaxException * @throws MalformedURLException * @throws IOException */ public static void addRemoteConfig(String remoteName, URIish uri, Repository repository) throws URISyntaxException, MalformedURLException, IOException { StoredConfig config = repository.getConfig(); RemoteConfig remoteConfig = new RemoteConfig(config, remoteName); remoteConfig.addURI(uri); remoteConfig.update(config); config.save(); }
From source file:org.jboss.tools.openshift.egit.core.EGitUtils.java
License:Open Source License
/** * Adds the given uri of a remote repository to the given repository by the * given name.//from w ww. j a va2 s .c o m * * @param remoteName * the name to use for the remote repository * @param uri * the uri of the remote repository * @param repository * the repository to add the remote to * @throws URISyntaxException * the uRI syntax exception * @throws MalformedURLException * the malformed url exception * @throws IOException * Signals that an I/O exception has occurred. */ public static void addRemoteTo(String remoteName, URIish uri, Repository repository) throws URISyntaxException, MalformedURLException, IOException { StoredConfig config = repository.getConfig(); RemoteConfig remoteConfig = new RemoteConfig(config, remoteName); remoteConfig.addURI(uri); remoteConfig.update(config); config.save(); }
From source file:org.jboss.tools.openshift.egit.internal.test.EGitUtilsTest.java
License:Open Source License
@Test public void shouldUserFetchSpecInConfig() throws Exception { testRepository.addRemoteTo(REPO2_REMOTE_NAME, testRepository2.getRepository()); // add custom fetch-spec in config (fetch = refs/heads/master:refs/remotes/bingo/master) StoredConfig config = testRepository.getRepository().getConfig(); config.getString(ConfigConstants.CONFIG_KEY_REMOTE, REPO2_REMOTE_NAME, "fetch"); String remoteTrackingBranchRef = "refs/remotes/bingo/master"; String fetchSpec = "refs/heads/master:" + remoteTrackingBranchRef; config.setString(ConfigConstants.CONFIG_KEY_REMOTE, REPO2_REMOTE_NAME, "fetch", fetchSpec); config.save(); EGitUtils.isAhead(testRepository.getRepository(), REPO2_REMOTE_NAME, null); // was remote tracking branch created? assertTrue(testRepository.getRepository().getAllRefs().containsKey(remoteTrackingBranchRef)); }
From source file:org.jboss.tools.openshift.egit.internal.test.util.TestRepository.java
License:Open Source License
public void addRemoteTo(String remoteName, Repository remoteRepository) throws URISyntaxException, MalformedURLException, IOException { StoredConfig config = repository.getConfig(); RemoteConfig remoteConfig = new RemoteConfig(config, remoteName); URIish uri = new URIish(remoteRepository.getDirectory().toURI().toURL()); remoteConfig.addURI(uri);/*from www .j a va2 s .c o m*/ remoteConfig.update(config); config.save(); }
From source file:org.jboss.tools.openshift.ui.bot.test.application.v3.adapter.ImportApplicationWizardGitTest.java
License:Open Source License
private void setRemote(Git repo, String remoteURL) { try {/*from ww w .j av a 2 s .c o m*/ StoredConfig config = repo.getRepository().getConfig(); config.setString("remote", "origin", "url", remoteURL); config.save(); } catch (IllegalStateException | IOException e) { e.printStackTrace(); fail(); } }
From source file:org.kie.commons.java.nio.fs.jgit.util.JGitUtil.java
License:Apache License
public static void syncRepository(final Git git, final CredentialsProvider credentialsProvider, final String origin, boolean force) throws InvalidRemoteException { if (origin == null || origin.isEmpty()) { fetchRepository(git, credentialsProvider); } else {//from w w w . j av a 2 s.co m try { final StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "upstream", "url", origin); config.save(); } catch (final Exception ex) { throw new RuntimeException(ex); } final List<RefSpec> specs = new ArrayList<RefSpec>(); specs.add(new RefSpec("+refs/heads/*:refs/remotes/upstream/*")); specs.add(new RefSpec("+refs/tags/*:refs/tags/*")); specs.add(new RefSpec("+refs/notes/*:refs/notes/*")); try { git.fetch().setCredentialsProvider(credentialsProvider).setRefSpecs(specs).setRemote(origin).call(); git.branchCreate().setName("master") .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM) .setStartPoint("upstream/master").setForce(true).call(); } catch (final InvalidRemoteException e) { throw e; } catch (final Exception ex) { throw new RuntimeException(ex); } } }
From source file:org.moxie.ant.Main.java
License:Apache License
private void initGit() throws GitAPIException { // create the repository InitCommand init = Git.init();// w w w . ja v a2 s. c o m init.setBare(false); init.setDirectory(newProject.dir); Git git = init.call(); if (!StringUtils.isEmpty(newProject.gitOrigin)) { // set the origin and configure the master branch for merging StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", getGitUrl()); config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"); config.setString("branch", "master", "remote", "origin"); config.setString("branch", "master", "merge", "refs/heads/master"); try { config.save(); } catch (IOException e) { throw new MoxieException(e); } } // prepare a common gitignore file StringBuilder sb = new StringBuilder(); sb.append("/.directory\n"); sb.append("/.DS_STORE\n"); sb.append("/.DS_Store\n"); sb.append("/.settings\n"); sb.append("/bin\n"); sb.append("/build\n"); sb.append("/ext\n"); sb.append("/target\n"); sb.append("/tmp\n"); sb.append("/temp\n"); if (!newProject.eclipse.includeClasspath()) { // ignore hard-coded .classpath sb.append("/.classpath\n"); } FileUtils.writeContent(new File(newProject.dir, ".gitignore"), sb.toString()); AddCommand add = git.add(); add.addFilepattern("build.xml"); add.addFilepattern("build.moxie"); add.addFilepattern(".gitignore"); if (newProject.eclipse.includeProject()) { add.addFilepattern(".project"); } if (newProject.eclipse.includeClasspath()) { // MOXIE_HOME relative dependencies in .classpath add.addFilepattern(".classpath"); } if (newProject.idea.includeProject()) { add.addFilepattern(".project"); } if (newProject.idea.includeClasspath()) { // MOXIE_HOME relative dependencies in .iml add.addFilepattern("*.iml"); } try { add.call(); CommitCommand commit = git.commit(); PersonIdent moxie = new PersonIdent("Moxie", "moxie@localhost"); commit.setAuthor(moxie); commit.setCommitter(moxie); commit.setMessage("Project structure created"); commit.call(); } catch (Exception e) { throw new MoxieException(e); } }
From source file:org.ms123.common.git.GitServiceImpl.java
License:Open Source License
public void addRemoteOrigin(@PName("name") String name, @PName("url") String url) { try {//from w ww .j av a 2s .co m String gitSpace = System.getProperty("git.repos"); File dir = new File(gitSpace, name); if (!dir.exists()) { throw new RpcException(ERROR_FROM_METHOD, 100, "GitService.setAddRemoteOrigin:Repo(" + name + ") not exists"); } Git git = Git.open(dir); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", url); config.save(); } catch (Exception e) { throw new RpcException(ERROR_FROM_METHOD, INTERNAL_SERVER_ERROR, "GitService.addRemoteOrigin:", e); } finally { } }
From source file:org.omegat.core.team.GITRemoteRepository.java
License:Open Source License
public void checkoutFullProject(String repositoryURL) throws Exception { Log.logInfoRB("GIT_START", "clone"); CloneCommand c = Git.cloneRepository(); c.setURI(repositoryURL);// www . ja v a2s .c o m c.setDirectory(localDirectory); try { c.call(); } catch (InvalidRemoteException e) { FileUtil.deleteTree(localDirectory); Throwable cause = e.getCause(); if (cause != null && cause instanceof org.eclipse.jgit.errors.NoRemoteRepositoryException) { BadRepositoryException bre = new BadRepositoryException( ((org.eclipse.jgit.errors.NoRemoteRepositoryException) cause).getLocalizedMessage()); bre.initCause(e); throw bre; } throw e; } repository = Git.open(localDirectory).getRepository(); new Git(repository).submoduleInit().call(); new Git(repository).submoduleUpdate().call(); //Deal with line endings. A normalized repo has LF line endings. //OmegaT uses line endings of OS for storing tmx files. //To do auto converting, we need to change a setting: StoredConfig config = repository.getConfig(); if ("\r\n".equals(FileUtil.LINE_SEPARATOR)) { //on windows machines, convert text files to CRLF config.setBoolean("core", null, "autocrlf", true); } else { //on Linux/Mac machines (using LF), don't convert text files //but use input format, unchanged. //NB: I don't know correct setting for OS'es like MacOS <= 9, // which uses CR. Git manual only speaks about converting from/to //CRLF, so for CR, you probably don't want conversion either. config.setString("core", null, "autocrlf", "input"); } config.save(); myCredentialsProvider.saveCredentials(); Log.logInfoRB("GIT_FINISH", "clone"); }