Git git = new Git(localRepository); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", "http://github.com/user/repo"); config.save();
StoredConfig config = git.getRepository().getConfig(); config.setBoolean("core", null, "sparseCheckout", true); 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 updateSslVerify(StoredConfig config, boolean value) { // Since git uses the original URI for matching, we must also use the // original URI and cannot use the current URI (which might be different // after redirects). String uriPattern = uri.getScheme() + "://" + uri.getHost(); //$NON-NLS-1$ int port = uri.getPort(); if (port > 0) { uriPattern += ":" + port; //$NON-NLS-1$ } config.setBoolean(HttpConfig.HTTP, uriPattern, HttpConfig.SSL_VERIFY_KEY, value); try { config.save(); } catch (IOException e) { LOG.error(JGitText.get().sslVerifyCannotSave, e); } }
/** * 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; }
/** * {@inheritDoc} * <p> * Executes the {@code remote} command with all the options and parameters * collected by the setter methods of this class. */ @Override public RemoteConfig call() throws GitAPIException { checkCallable(); try { StoredConfig config = repo.getConfig(); RemoteConfig remote = new RemoteConfig(config, name); config.unsetSection(ConfigConstants.CONFIG_KEY_REMOTE, name); config.save(); return remote; } catch (IOException | URISyntaxException e) { throw new JGitInternalException(e.getMessage(), e); } }
config.save(); return remote; } catch (IOException | URISyntaxException 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(); }
config.save(); return initialized; } catch (IOException e) {
/** * {@inheritDoc} * <p> * Executes the {@code remote add} command with all the options and * parameters collected by the setter methods of this class. */ @Override public RemoteConfig call() throws GitAPIException { checkCallable(); try { StoredConfig config = repo.getConfig(); RemoteConfig remote = new RemoteConfig(config, name); RefSpec refSpec = new RefSpec(); refSpec = refSpec.setForceUpdate(true); refSpec = refSpec.setSourceDestination(Constants.R_HEADS + "*", //$NON-NLS-1$ Constants.R_REMOTES + name + "/*"); //$NON-NLS-1$ remote.addFetchRefSpec(refSpec); remote.addURI(uri); remote.update(config); config.save(); return remote; } catch (IOException | URISyntaxException e) { throw new JGitInternalException(e.getMessage(), e); } }
ConfigConstants.CONFIG_BRANCH_SECTION, shortenedName); cfg.save();
repoConfig.save();
ConfigConstants.CONFIG_KEY_URL, resolvedUri); try { config.save(); } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e);
private FetchResult fetch(Repository clonedRepo, URIish u) throws URISyntaxException, org.eclipse.jgit.api.errors.TransportException, IOException, GitAPIException { // create the remote config and save it RemoteConfig config = new RemoteConfig(clonedRepo.getConfig(), remote); config.addURI(u); final String dst = (bare ? Constants.R_HEADS : Constants.R_REMOTES + config.getName() + '/') + '*'; boolean fetchAll = cloneAllBranches || branchesToClone == null || branchesToClone.isEmpty(); config.setFetchRefSpecs(calculateRefSpecs(fetchAll, dst)); config.update(clonedRepo.getConfig()); clonedRepo.getConfig().save(); // run the fetch command FetchCommand command = new FetchCommand(clonedRepo); command.setRemote(remote); command.setProgressMonitor(monitor); command.setTagOpt(fetchAll ? TagOpt.FETCH_TAGS : TagOpt.AUTO_FOLLOW); configure(command); return command.call(); }
name, ConfigConstants.CONFIG_KEY_MERGE, baseBranch); config.save();
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 setDefaultUser(@Nonnull String name, @Nonnull String email, @Nonnull Repository repo) throws IOException { StoredConfig config = repo.getConfig(); config.setString("user", null, "name", name); config.setString("user", null, "email", email); config.save(); }
@Override public boolean performFinish() { configureRemoteSection(); configureCreateChangeId(); try { config.save(); } catch (IOException e) { gerritConfiguration.setErrorMessage(e.getMessage()); return false; } return true; }
private void updateWithBundleTimestamp(Repository repo, Bundle bundle) throws IOException { StoredConfig config = repo.getConfig(); config.setLong("speakeasy", null, BUNDLELASTMODIFIED, bundle.getLastModified()); config.save(); }