@Autowired public ConfigRepository(SystemEnvironment systemEnvironment) throws IOException { this.systemEnvironment = systemEnvironment; workingDir = this.systemEnvironment.getConfigRepoDir(); File configRepoDir = new File(workingDir, ".git"); gitRepo = new FileRepositoryBuilder().setGitDir(configRepoDir).build(); gitRepo.getConfig().setInt("gc", null, "auto", 0); git = new Git(gitRepo); }
/** * @param gitConfigFolder e.g. /your/project/root/.git * * @return Returns git config remote.origin.url field of the repository located at gitConfigFolder */ public static String getGitRemoteUrl( String gitConfigFolder ) throws MojoExecutionException { try { Repository repo = new RepositoryBuilder().setGitDir( new File( gitConfigFolder ) ).readEnvironment().findGitDir() .build(); Config config = repo.getConfig(); return config.getString( "remote", "origin", "url" ); } catch ( Exception e ) { throw new MojoExecutionException( "Error trying to get remote origin url of git repository", e ); } }
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; }
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; } }
/** * Create a configuration honoring the repository's settings. * * @param db * the repository to read settings from. The repository is not * retained by the new configuration, instead its settings are * copied during the constructor. * @since 5.1.4 */ public TransferConfig(Repository db) { this(db.getConfig()); }
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; } }
this.git = Git.open(repoDirFile); String uri = this.git.getRepository().getConfig().getString("remote", REMOTE_NAME, "url");
@Override public String getBuildAuthorName() throws GitCommitIdExecutionException { String userName = git.getConfig().getString("user", null, "name"); return Optional.ofNullable(userName).orElse(""); }
@Override public String getBuildAuthorEmail() throws GitCommitIdExecutionException { String userEmail = git.getConfig().getString("user", null, "email"); return Optional.ofNullable(userEmail).orElse(""); }
/** * Create a configuration honoring the repository's settings. * * @param db * the repository to read settings from. The repository is not * retained by the new configuration, instead its settings are * copied during the constructor. */ public ReftableConfig(Repository db) { fromConfig(db.getConfig()); }
/** * Reset generator and start new submodule walk * * @return this generator */ public SubmoduleWalk reset() { repoConfig = repository.getConfig(); modulesConfig = null; pathToName = null; walk.reset(); return this; }
/** * Create a new rename detector for the given repository * * @param repo * the repository to use for rename detection */ public RenameDetector(Repository repo) { this(repo.newObjectReader(), repo.getConfig().get(DiffConfig.KEY)); }
/** * Get the names of all known remotes * * @return the names of all known remotes * @since 3.4 */ @NonNull public Set<String> getRemoteNames() { return getConfig() .getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION); }
@Override public String getRemoteOriginUrl() throws GitCommitIdExecutionException { String url = git.getConfig().getString("remote", "origin", "url"); return stripCredentialsFromOriginUrl(url); }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Config storedConfig = repository.getConfig(); Set<String> remotes = storedConfig.getSubsections("remote"); for (String remoteName : remotes) { String url = storedConfig.getString("remote", remoteName, "url"); System.out.println(remoteName + " " + url); } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Config storedConfig = repository.getConfig(); Set<String> remotes = storedConfig.getSubsections("remote"); for (String remoteName : remotes) { String url = storedConfig.getString("remote", remoteName, "url"); System.out.println(remoteName + " " + url); } } } }
private boolean isEnabledFor(Repository db) { if (isOverridable()) return db.getConfig().get(configKey).enabled; return isEnabled(); }
private FastForwardMode getFastForwardMode() { if (fastForwardMode != null) { return fastForwardMode; } Config config = repo.getConfig(); Merge ffMode = config.getEnum(Merge.values(), ConfigConstants.CONFIG_PULL_SECTION, null, ConfigConstants.CONFIG_KEY_FF, null); return ffMode != null ? FastForwardMode.valueOf(ffMode) : null; } }
TransportHttp(Repository local, URIish uri) throws NotSupportedException { super(local, uri); setURI(uri); http = new HttpConfig(local.getConfig(), uri); proxySelector = ProxySelector.getDefault(); sslVerify = http.isSslVerify(); }