Refine search
this.git = Git.open(repoDirFile); String uri = this.git.getRepository().getConfig().getString("remote", REMOTE_NAME, "url"); this.git = Git.cloneRepository() .setDirectory(repoDirFile) .setURI(this.repoUri)
/** * 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; }
/** * Whether to remove refs which no longer exist in the source * * @return whether to remove refs which no longer exist in the source */ public boolean isRemoveDeletedRefs() { if (removeDeletedRefs != null) return removeDeletedRefs.booleanValue(); else { // fall back to configuration boolean result = false; StoredConfig config = repo.getConfig(); result = config.getBoolean(ConfigConstants.CONFIG_FETCH_SECTION, null, ConfigConstants.CONFIG_KEY_PRUNE, result); result = config.getBoolean(ConfigConstants.CONFIG_REMOTE_SECTION, remote, ConfigConstants.CONFIG_KEY_PRUNE, result); return result; } }
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(); }
/** * * @return the name of the master branch */ public String getMaster() { return git.getRepository().getConfig().getString(JGitFlowConstants.SECTION, ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER); }
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; } }
CloneCommand clone = Git.cloneRepository(); configure(clone); clone.setDirectory(moduleDirectory); clone.setGitDir(new File(new File(repo.getDirectory(), Constants.MODULES), path)); clone.setURI(resolvedUri); Repository subRepo = null; try (Git git = clone.call()) { subRepo = git.getRepository(); subRepo.incrementOpen(); StoredConfig config = repo.getConfig(); config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, name, ConfigConstants.CONFIG_KEY_URL, resolvedUri); try { config.save(); } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e);
if (!paths.isEmpty()) generator.setFilter(PathFilterGroup.createFromStrings(paths)); StoredConfig config = repo.getConfig(); List<String> initialized = new ArrayList<>(); while (generator.next()) { 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) config.save(); return initialized; } catch (IOException e) {
private void setSparseCheckout(File gitDir, Set<String> checkoutFiles) throws GitException { try (Git git = gitOpen()) { StoredConfig config = git.getRepository().getConfig(); config.setBoolean("core", null, "sparseCheckout", true); config.save();
else { RevCommit commit = revWalk.parseCommit(repo .resolve(getStartPointOrHead())); baseCommit = commit.getShortMessage(); else { String autosetupflag = repo.getConfig().getString( ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOSETUPMERGE); .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.save();
protected boolean shouldPull(Git git) throws GitAPIException { boolean shouldPull; if (this.refreshRate > 0 && System.currentTimeMillis() - this.lastRefresh < (this.refreshRate * 1000)) { return false; } Status gitStatus = git.status().call(); boolean isWorkingTreeClean = gitStatus.isClean(); String originUrl = git.getRepository().getConfig().getString("remote", "origin", "url"); if (this.forcePull && !isWorkingTreeClean) { shouldPull = true; logDirty(gitStatus); } else { shouldPull = isWorkingTreeClean && originUrl != null; } if (!isWorkingTreeClean && !this.forcePull) { this.logger.info("Cannot pull from remote " + originUrl + ", the working tree is not clean."); } return shouldPull; }
private MergeResult merge(Git git, String label) { try { MergeCommand merge = git.merge(); merge.include(git.getRepository().findRef("origin/" + label)); MergeResult result = merge.call(); if (!result.getMergeStatus().isSuccessful()) { this.logger.warn("Merged from remote " + label + " with result " + result.getMergeStatus()); } return result; } catch (Exception ex) { String message = "Could not merge remote for " + label + " remote: " + git .getRepository().getConfig().getString("remote", "origin", "url"); warn(message, ex); return null; } }
protected FetchResult fetch(Git git, String label) { FetchCommand fetch = git.fetch(); fetch.setRemote("origin"); fetch.setTagOpt(TagOpt.FETCH_TAGS); fetch.setRemoveDeletedRefs(deleteUntrackedBranches); if (this.refreshRate > 0) { this.setLastRefresh(System.currentTimeMillis()); } configureCommand(fetch); try { FetchResult result = fetch.call(); if (result.getTrackingRefUpdates() != null && result.getTrackingRefUpdates().size() > 0) { logger.info("Fetched for remote " + label + " and found " + result.getTrackingRefUpdates().size() + " updates"); } return result; } catch (Exception ex) { String message = "Could not fetch remote for " + label + " remote: " + git .getRepository().getConfig().getString("remote", "origin", "url"); warn(message, ex); return null; } }
private Ref resetHard(Git git, String label, String ref) { ResetCommand reset = git.reset(); reset.setRef(ref); reset.setMode(ResetType.HARD); try { Ref resetRef = reset.call(); if (resetRef != null) { this.logger.info( "Reset label " + label + " to version " + resetRef.getObjectId()); } return resetRef; } catch (Exception ex) { String message = "Could not reset to remote for " + label + " (current ref=" + ref + "), remote: " + git.getRepository().getConfig() .getString("remote", "origin", "url"); warn(message, ex); return null; } }
/** * @param gitBasedRepositoryConfiguration the configuration of the repository * @throws IOException thrown if repository does not exist * @throws GitAPIException thrown if there was an error while checking the status of the repository * @throws NoWorkTreeException thrown if the directory is not a git work tree */ public GitBasedRepository(GitBasedRepositoryConfiguration gitBasedRepositoryConfiguration) throws IOException, NoWorkTreeException, GitAPIException { super(Objects.requireNonNull(gitBasedRepositoryConfiguration)); this.gitBasedRepositoryConfiguration = gitBasedRepositoryConfiguration; FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository gitRepo = builder.setWorkTree(this.repositoryRoot.toFile()).setMustExist(false).build(); if (!Files.exists(this.repositoryRoot.resolve(".git"))) { gitRepo.create(); } // explicitly enable longpaths to ensure proper handling of long pathss gitRepo.getConfig().setBoolean("core", null, "longpaths", true); gitRepo.getConfig().save(); this.eventBus = new EventBus(); this.git = new Git(gitRepo); if (gitBasedRepositoryConfiguration.isAutoCommit() && !this.git.status().call().isClean()) { this.addCommit("Files changed externally."); } }
return result; try { String currentBranch = repo.getFullBranch(); if (!force) { .parseCommit(repo.resolve(Constants.HEAD)); for (String branchName : branchNames) { if (branchName == null) continue; Ref currentRef = repo.findRef(branchName); if (currentRef == null) continue; final StoredConfig cfg = repo.getConfig(); cfg.unsetSection( ConfigConstants.CONFIG_BRANCH_SECTION, shortenedName); cfg.save();
CommitIdDatabase(Repository repo) { // NB: We enable fsync only when our Git repository has been configured so, // because there's no point of doing fsync only on this file when the // Git repository does not. this(repo.getDirectory(), repo.getConfig().getBoolean(CONFIG_CORE_SECTION, "fsyncObjectFiles", false)); }
/** * Creates new PersonIdent from config info in repository, with current time. * This new PersonIdent gets the info from the default committer as available * from the configuration. * * @param repo a {@link org.eclipse.jgit.lib.Repository} object. */ public PersonIdent(Repository repo) { this(repo.getConfig().get(UserConfig.KEY)); }