/** * @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 ); } }
/** * Retrieves the config value of user.signingKey. * * @return the value of user.signingKey (may be <code>null</code>) */ public String getSigningKey() { return config.getString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_SIGNINGKEY); }
/** * Get the remote this branch is configured to fetch from/push to * * @return the remote this branch is configured to fetch from/push to, or * {@code null} if not defined * @since 3.5 */ public String getRemote() { return config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE); }
/** * Get the name of the upstream branch as it is called on the remote * * @return the name of the upstream branch as it is called on the remote, or * {@code null} if not defined * @since 3.5 */ public String getMerge() { return config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE); }
private static String getLocalName(Config cfg) { return cfg.getString(CONFIG_SECTION_KETCH, null, CONFIG_KEY_NAME); }
private static boolean hasParticipation(Config cfg, String name) { return cfg.getString(CONFIG_KEY_REMOTE, name, CONFIG_KEY_TYPE) != null; }
private static String[] getMergeOptions(String branch, Config config) { String mergeOptions = config.getString( ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_MERGEOPTIONS); if (mergeOptions != null) return mergeOptions.split("\\s"); //$NON-NLS-1$ else return new String[0]; }
private void loadPathNames() { pathToName = null; if (modulesConfig != null) { HashMap<String, String> pathNames = new HashMap<>(); for (String name : modulesConfig .getSubsections(ConfigConstants.CONFIG_SUBMODULE_SECTION)) { pathNames.put(modulesConfig.getString( ConfigConstants.CONFIG_SUBMODULE_SECTION, name, ConfigConstants.CONFIG_KEY_PATH), name); } pathToName = pathNames; } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Config config = repository.getConfig(); String name = config.getString("user", null, "name"); String email = config.getString("user", null, "email"); if (name == null || email == null) { System.out.println("User identity is unknown!"); } else { System.out.println("User identity is " + name + " <" + email + ">"); } String url = config.getString("remote", "origin", "url"); if (url != null) { System.out.println("Origin comes from " + url); } } } }
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { Config config = repository.getConfig(); String name = config.getString("user", null, "name"); String email = config.getString("user", null, "email"); if (name == null || email == null) { System.out.println("User identity is unknown!"); } else { System.out.println("User identity is " + name + " <" + email + ">"); } String url = config.getString("remote", "origin", "url"); if (url != null) { System.out.println("Origin comes from " + url); } } } }
private CoreConfig(Config rc) { compression = rc.getInt(ConfigConstants.CONFIG_CORE_SECTION, ConfigConstants.CONFIG_KEY_COMPRESSION, DEFAULT_COMPRESSION); packIndexVersion = rc.getInt(ConfigConstants.CONFIG_PACK_SECTION, ConfigConstants.CONFIG_KEY_INDEXVERSION, 2); logAllRefUpdates = rc.getBoolean(ConfigConstants.CONFIG_CORE_SECTION, ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES, true); excludesfile = rc.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_EXCLUDESFILE); attributesfile = rc.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_ATTRIBUTESFILE); }
SignedPushConfig(Config cfg) { setCertNonceSeed(cfg.getString("receive", null, "certnonceseed")); //$NON-NLS-1$ //$NON-NLS-2$ certNonceSlopLimit = cfg.getInt("receive", "certnonceslop", 0); //$NON-NLS-1$ //$NON-NLS-2$ }
/** * Get the configured remote URL for current entry. This will be the value * from the .gitmodules file in the current repository's working tree. * * @return configured URL * @throws org.eclipse.jgit.errors.ConfigInvalidException * @throws java.io.IOException */ public String getModulesUrl() throws IOException, ConfigInvalidException { lazyLoadModulesConfig(); return modulesConfig.getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, getModuleName(), ConfigConstants.CONFIG_KEY_URL); }
/** * Get the configured update field for current entry. This will be the value * from the .gitmodules file in the current repository's working tree. * * @return update value * @throws org.eclipse.jgit.errors.ConfigInvalidException * @throws java.io.IOException */ public String getModulesUpdate() throws IOException, ConfigInvalidException { lazyLoadModulesConfig(); return modulesConfig.getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, getModuleName(), ConfigConstants.CONFIG_KEY_UPDATE); }
/** * Get the configured path for current entry. This will be the value from * the .gitmodules file in the current repository's working tree. * * @return configured path * @throws org.eclipse.jgit.errors.ConfigInvalidException * @throws java.io.IOException */ public String getModulesPath() throws IOException, ConfigInvalidException { lazyLoadModulesConfig(); return modulesConfig.getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, getModuleName(), ConfigConstants.CONFIG_KEY_PATH); }
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 DiffConfig(Config rc) { noPrefix = rc.getBoolean(ConfigConstants.CONFIG_DIFF_SECTION, ConfigConstants.CONFIG_KEY_NOPREFIX, false); renameDetectionType = parseRenameDetectionType(rc.getString( ConfigConstants.CONFIG_DIFF_SECTION, null, ConfigConstants.CONFIG_KEY_RENAMES)); renameLimit = rc.getInt(ConfigConstants.CONFIG_DIFF_SECTION, ConfigConstants.CONFIG_KEY_RENAMELIMIT, 400); }
private static String getEmailInternal(Config rc, String envKey) { // try to get the email for the system property GIT_XXX_EMAIL String email = system().getenv(envKey); if (email == null) { // try to get the email from the local and global configurations. email = rc.getString("user", null, "email"); //$NON-NLS-1$ //$NON-NLS-2$ } return stripInvalidCharacters(email); }
private static String getNameInternal(Config rc, String envKey) { // try to get the user name for the system property GIT_XXX_NAME String username = system().getenv(envKey); if (username == null) { // try to get the user name from the local and global // configurations. username = rc.getString("user", null, "name"); //$NON-NLS-1$ //$NON-NLS-2$ } return stripInvalidCharacters(username); }