List of usage examples for org.eclipse.jgit.lib StoredConfig setString
public void setString(final String section, final String subsection, final String name, final String value)
From source file:ru.nikitenkogleb.androidtools.newappwizard.GitSupport.java
/** Creates new Git Support module */ public GitSupport(String login, String password, String repository, String projectPath, String tempFolder, String initBranch) {//from w w w .jav a2s.c o m final String home = System.getProperty("user.home"); if (login == null || login.isEmpty()) { mSshConfigCallback = new SSHConfigCallback(home + Path.SEPARATOR + ".ssh" + Path.SEPARATOR + "id_rsa", new CredentialsProvider(password)); mHttpsCredentialsProvider = null; } else { mSshConfigCallback = null; mHttpsCredentialsProvider = new UsernamePasswordCredentialsProvider(login, password); } try { final CloneCommand cloneCommand = Git.cloneRepository().setURI(repository) .setDirectory(new File(tempFolder)); if (mSshConfigCallback != null) cloneCommand.setTransportConfigCallback(mSshConfigCallback); else cloneCommand.setCredentialsProvider(mHttpsCredentialsProvider); final Git mGit = cloneCommand.call(); try { mGit.checkout().setCreateBranch(true).setName(initBranch).call(); } catch (RefNotFoundException e) { e.printStackTrace(); final StoredConfig config = mGit.getRepository().getConfig(); config.setString("remote", "origin", "url", repository); config.save(); } mGit.close(); move(new File(tempFolder + "/.git"), new File(projectPath + "/.git")); move(new File(tempFolder + "/README.md"), new File(projectPath + "/README.md")); move(new File(tempFolder + "/LICENSE"), new File(projectPath + "/LICENSE")); move(new File(tempFolder + "/.gitignore"), new File(projectPath + "/.gitignore")); new File(tempFolder).delete(); mProjectPath = projectPath; } catch (GitAPIException | IOException e) { e.printStackTrace(); } }
From source file:sh.isaac.provider.sync.git.SyncServiceGIT.java
License:Apache License
/** * Relink remote./*from ww w. j a va2s. c om*/ * * @param remoteAddress the remote address * @param username the username * @param password the password * @throws IllegalArgumentException the illegal argument exception * @throws IOException Signals that an I/O exception has occurred. * @see sh.isaac.api.sync.SyncFiles#relinkRemote(java.lang.String, java.lang.String, java.lang.String) */ @Override public void relinkRemote(String remoteAddress, String username, char[] password) throws IllegalArgumentException, IOException { try (Git git = getGit()) { LOG.debug("Configuring remote URL and fetch defaults to {}", remoteAddress); final StoredConfig sc = git.getRepository().getConfig(); sc.setString("remote", "origin", "url", remoteAddress); sc.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"); sc.save(); } }