Git git = new Git(localRepository); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", "http://github.com/user/repo"); config.save();
private void configRemote(StoredConfig config, String name, String url) throws GitException { try { config.setString("remote", name, "url", url); config.setString("remote", name, "fetch", "+refs/heads/*:refs/remotes/origin/*"); config.save(); } catch (IOException e) { throw new GitException("Fail to config remote git url", e); } }
private void addMergeConfig(Repository clonedRepo, Ref head) throws IOException { String branchName = Repository.shortenRefName(head.getName()); clonedRepo.getConfig().setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE, remote); clonedRepo.getConfig().setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE, head.getName()); String autosetupRebase = clonedRepo.getConfig().getString( ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOSETUPREBASE); if (ConfigConstants.CONFIG_KEY_ALWAYS.equals(autosetupRebase) || ConfigConstants.CONFIG_KEY_REMOTE.equals(autosetupRebase)) clonedRepo.getConfig().setEnum( ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REBASE, BranchRebaseMode.REBASE); clonedRepo.getConfig().save(); }
/** * Setting remote url to local repo * * @param path * @param remoteName * @param remoteUrl * @return * @throws GitException */ public static Path remoteSet(Path path, String remoteName, String remoteUrl) throws GitException { try (Git git = Git.open(path.toFile())) { StoredConfig config = git.getRepository().getConfig(); config.setString("remote", remoteName, "url", remoteUrl); config.save(); } catch (IOException e) { throw new GitException("set remote url exception", e); } return path; }
String update = generator.getModulesUpdate(); if (url != null) config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, name, ConfigConstants.CONFIG_KEY_URL, url); if (update != null) config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, name, ConfigConstants.CONFIG_KEY_UPDATE, update); if (url != null || update != null)
.shortenRemoteBranchName(baseBranch); config .setString(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_REMOTE, remoteName); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_MERGE, Constants.R_HEADS + branchName); } else { config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_REMOTE, "."); //$NON-NLS-1$ config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_MERGE, baseBranch);
config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, name, ConfigConstants.CONFIG_KEY_URL, resolvedUri); try {
public void add(Path path, String... branches) { final StoredConfig config = getConfig().getConfig(); config.setString(ConfigConstants.CONFIG_REMOTE_SECTION, name, ConfigConstants.CONFIG_KEY_URL, path.toString()); if ((branches == null) || (branches.length < 1)) branches = new String[] { "*" }; for (String branch : branches) { config.setString(ConfigConstants.CONFIG_REMOTE_SECTION, name, ConfigConstants.CONFIG_FETCH_SECTION, String.format("+refs/heads/%2$s:refs/remotes/%1$s/%2$s", name, branch)); } }
public Repository createCommit(File srcFolder, String applicationName) throws IOException, GitAPIException { Repository repository = repositoryService.createRepository(new Repository().setName(applicationName)); String cloneUrl = repository.getCloneUrl(); InitCommand init = new InitCommand(); init.setDirectory(srcFolder); init.setBare(false); Git git = init.call(); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", cloneUrl); config.save(); UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(accessToken, ""); git.add().addFilepattern(".").call(); git.commit().setMessage(COMMIT_MESSAGE).call(); git.push().setCredentialsProvider(user).call(); return repository; } }
public static void configureBranch(Git git, String branch, String origin, String remoteRepository) { // lets update the merge config if (!Strings.isNullOrBlank(branch)) { StoredConfig config = git.getRepository().getConfig(); config.setString("branch", branch, "remote", origin); config.setString("branch", branch, "merge", "refs/heads/" + branch); config.setString("remote", origin, "url", remoteRepository); config.setString("remote", origin, "fetch", "+refs/heads/*:refs/remotes/" + origin + "/*"); try { config.save(); } catch (IOException e) { LOG.error("Failed to save the git configuration to " + git.getRepository().getDirectory() + " with branch " + branch + " on " + origin + " remote repo: " + remoteRepository + " due: " + e.getMessage() + ". This exception is ignored.", e); } } }
public void setRemote(String remote) { String currentRemote = getRemote(); if (currentRemote != null && currentRemote.equals(remote)) { return; } try { StoredConfig config = getConfig(); config.setString("remote", REMOTE_NAME, "url", remote); config.save(); } catch (IOException e) { e.printStackTrace(); } }
private void setSubsection(String subsection, String value) { if (value == null || value.equals("")) { mConfig.unset(USER_SECTION, null, subsection); } else { mConfig.setString(USER_SECTION, null, subsection, value); } try { mConfig.save(); } catch (IOException e) { Timber.e(e); } }
/** {@inheritDoc} */ @Deprecated @Override public void setSubmoduleUrl(String name, String url) throws GitException, InterruptedException { try (Repository repo = getRepository()) { StoredConfig config = repo.getConfig(); config.setString("submodule", name, "url", url); config.save(); } catch (IOException e) { throw new GitException(e); } }
/** {@inheritDoc} */ @Deprecated @Override public void setRemoteUrl(String name, String url, String GIT_DIR) throws GitException, InterruptedException { try (Repository repo = new RepositoryBuilder().setGitDir(new File(GIT_DIR)).build()) { StoredConfig config = repo.getConfig(); config.setString("remote", name, "url", url); config.save(); } catch (IOException ioe) { throw new GitException(ioe); } }
/** {@inheritDoc} */ @Override public void setRemoteUrl(String name, String url) throws GitException { try (Repository repo = getRepository()) { StoredConfig config = repo.getConfig(); config.setString("remote", name, "url", url); config.save(); } catch (IOException e) { throw new GitException(e); } }