private String setupOriginIfNeeded(Git git, StoredConfig gitConfig, String originUrl) throws IOException, ConfigInvalidException { String newOriginUrl = originUrl; //set origin if we need to if ((Strings.isNullOrEmpty(originUrl) || alwaysUpdateOrigin) && !Strings.isNullOrEmpty(defaultOriginUrl)) { if (defaultOriginUrl.startsWith("file://")) { File originFile = new File(defaultOriginUrl.substring(7)); newOriginUrl = "file://" + originFile.getCanonicalPath(); } else { newOriginUrl = defaultOriginUrl; } gitConfig.setString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, "url", newOriginUrl); gitConfig.setString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, "fetch", "+refs/heads/*:refs/remotes/origin/*"); gitConfig.save(); gitConfig.load(); } return newOriginUrl; }
private String setupOriginIfNeeded(Git git, StoredConfig gitConfig, String originUrl) throws IOException, ConfigInvalidException { String newOriginUrl = originUrl; //set origin if we need to if ((Strings.isNullOrEmpty(originUrl) || alwaysUpdateOrigin) && !Strings.isNullOrEmpty(defaultOriginUrl)) { if (defaultOriginUrl.startsWith("file://")) { File originFile = new File(defaultOriginUrl.substring(7)); newOriginUrl = "file://" + originFile.getCanonicalPath(); } else { newOriginUrl = defaultOriginUrl; } gitConfig.setString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, "url", newOriginUrl); gitConfig.setString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, "fetch", "+refs/heads/*:refs/remotes/origin/*"); gitConfig.save(); gitConfig.load(); } return newOriginUrl; }
void setConfig(FileBasedConfig config) throws IOException { editableConfig = config; try { editableConfig.clear(); editableConfig.load(); } catch (ConfigInvalidException e) { throw new IOException(e.getMessage()); } initControlsFromConfig(); }
private static StoredConfig loadRepoScopedConfig(Repository repo) { StoredConfig c = repo.getConfig(); try { c.load(); } catch (IOException e) { Activator.handleError(e.getMessage(), e, true); } catch (ConfigInvalidException e) { Activator.handleError(e.getMessage(), e, true); } return c; }
public IPropertyDescriptor[] getPropertyDescriptors() { try { myConfig.load(); } catch (IOException e) { Activator.handleError( UIText.RepositoryRemotePropertySource_ErrorHeader, e, true); } catch (ConfigInvalidException e) { Activator.handleError( UIText.RepositoryRemotePropertySource_ErrorHeader, e, true); } List<IPropertyDescriptor> resultList = new ArrayList<IPropertyDescriptor>(); PropertyDescriptor desc = new PropertyDescriptor(RepositoriesView.URL, UIText.RepositoryRemotePropertySource_RemoteFetchURL_label); resultList.add(desc); desc = new PropertyDescriptor(RepositoriesView.FETCH, UIText.RepositoryRemotePropertySource_FetchLabel); resultList.add(desc); desc = new PropertyDescriptor(RepositoriesView.PUSHURL, UIText.RepositoryRemotePropertySource_RemotePushUrl_label); resultList.add(desc); desc = new PropertyDescriptor(RepositoriesView.PUSH, UIText.RepositoryRemotePropertySource_PushLabel); resultList.add(desc); return resultList.toArray(new IPropertyDescriptor[resultList.size()]); }
private static StoredConfig loadUserScopedConfig() { StoredConfig c = SystemReader.getInstance().openUserConfig(null, FS.DETECTED); try { c.load(); } catch (IOException e) { Activator.handleError(e.getMessage(), e, true); } catch (ConfigInvalidException e) { Activator.handleError(e.getMessage(), e, true); } return c; }
private void initControlsFromConfig() { try { editableConfig.load(); tv.setInput(new GitConfig(editableConfig)); editable = true; if (editableConfig instanceof FileBasedConfig) { FileBasedConfig fileConfig = (FileBasedConfig) editableConfig; File configFile = fileConfig.getFile(); if (configFile != null) if (isWriteable(configFile)) location.setText(configFile.getPath()); else { location.setText(NLS .bind(UIText.ConfigurationEditorComponent_ReadOnlyLocationFormat, configFile.getPath())); editable = false; } else { location.setText(UIText.ConfigurationEditorComponent_NoConfigLocationKnown); editable = false; } } } catch (IOException e) { Activator.handleError(e.getMessage(), e, true); } catch (ConfigInvalidException e) { Activator.handleError(e.getMessage(), e, true); } tv.expandAll(); updateEnablement(); }
/** * Sets the value for a given prefix * * @param prefixName * @param prefixValue * @throws com.atlassian.jgitflow.core.exception.JGitFlowIOException */ public void setPrefix(String prefixName, String prefixValue) throws JGitFlowIOException { StoredConfig config = git.getRepository().getConfig(); if (getPrefixNames().contains(prefixName)) { config.setString(JGitFlowConstants.SECTION, JGitFlowConstants.PREFIX_SUB, prefixName, prefixValue); try { config.save(); config.load(); } catch (Exception e) { throw new JGitFlowIOException(e); } } }
/** * Sets the value for a given prefix * * @param prefixName * @param prefixValue * @throws com.atlassian.jgitflow.core.exception.JGitFlowIOException */ public void setPrefix(String prefixName, String prefixValue) throws JGitFlowIOException { StoredConfig config = git.getRepository().getConfig(); if (getPrefixNames().contains(prefixName)) { config.setString(JGitFlowConstants.SECTION, JGitFlowConstants.PREFIX_SUB, prefixName, prefixValue); try { config.save(); config.load(); } catch (Exception e) { throw new JGitFlowIOException(e); } } }
/** * Sets the name of the master branch * * @param branchName * @throws com.atlassian.jgitflow.core.exception.JGitFlowIOException */ public void setMaster(String branchName) throws JGitFlowIOException { StoredConfig config = git.getRepository().getConfig(); config.setString(JGitFlowConstants.SECTION, ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER, branchName); try { config.save(); config.load(); } catch (Exception e) { throw new JGitFlowIOException(e); } }
/** * Sets the name of the master branch * * @param branchName * @throws com.atlassian.jgitflow.core.exception.JGitFlowIOException */ public void setMaster(String branchName) throws JGitFlowIOException { StoredConfig config = git.getRepository().getConfig(); config.setString(JGitFlowConstants.SECTION, ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER, branchName); try { config.save(); config.load(); } catch (Exception e) { throw new JGitFlowIOException(e); } }
/** * Sets the name of the develop branch * * @param branchName * @throws com.atlassian.jgitflow.core.exception.JGitFlowIOException */ public void setDevelop(String branchName) throws JGitFlowIOException { StoredConfig config = git.getRepository().getConfig(); config.setString(JGitFlowConstants.SECTION, ConfigConstants.CONFIG_BRANCH_SECTION, JGitFlowConstants.DEVELOP_KEY, branchName); try { config.save(); config.load(); } catch (Exception e) { throw new JGitFlowIOException(e); } }
/** * Sets the name of the develop branch * * @param branchName * @throws com.atlassian.jgitflow.core.exception.JGitFlowIOException */ public void setDevelop(String branchName) throws JGitFlowIOException { StoredConfig config = git.getRepository().getConfig(); config.setString(JGitFlowConstants.SECTION, ConfigConstants.CONFIG_BRANCH_SECTION, JGitFlowConstants.DEVELOP_KEY, branchName); try { config.save(); config.load(); } catch (Exception e) { throw new JGitFlowIOException(e); } }
private void list(StoredConfig config) throws IOException, ConfigInvalidException { config.load(); Set<String> sections = config.getSections(); for (String section : sections) { Set<String> names = config.getNames(section); for (String name : names) { for (String value : config.getStringList(section, null, name)) outw.println(section + "." + name + "=" + value); //$NON-NLS-1$ //$NON-NLS-2$ } if (names.isEmpty()) { for (String subsection : config.getSubsections(section)) { names = config.getNames(section, subsection); for (String name : names) { for (String value : config.getStringList(section, subsection, name)) outw.println(section + "." + subsection + "." //$NON-NLS-1$ //$NON-NLS-2$ + name + "=" + value); //$NON-NLS-1$ } } } } } }
private void setupRemotesInConfig(StoredConfig gitConfig, String originUrl) throws IOException, ConfigInvalidException { if (!Strings.isNullOrEmpty(originUrl)) { if (Strings.isNullOrEmpty(gitConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, context.getMaster(), "remote"))) { gitConfig.setString(ConfigConstants.CONFIG_BRANCH_SECTION, context.getMaster(), "remote", Constants.DEFAULT_REMOTE_NAME); } if (Strings.isNullOrEmpty(gitConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, context.getMaster(), "merge"))) { gitConfig.setString(ConfigConstants.CONFIG_BRANCH_SECTION, context.getMaster(), "merge", Constants.R_HEADS + context.getMaster()); } if (Strings.isNullOrEmpty(gitConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, context.getDevelop(), "remote"))) { gitConfig.setString(ConfigConstants.CONFIG_BRANCH_SECTION, context.getDevelop(), "remote", Constants.DEFAULT_REMOTE_NAME); } if (Strings.isNullOrEmpty(gitConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, context.getDevelop(), "merge"))) { gitConfig.setString(ConfigConstants.CONFIG_BRANCH_SECTION, context.getDevelop(), "merge", Constants.R_HEADS + context.getDevelop()); } if (Strings.isNullOrEmpty(gitConfig.getString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, "fetch"))) { gitConfig.setString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, "fetch", "+refs/heads/*:refs/remotes/origin/*"); } gitConfig.save(); gitConfig.load(); } }
private void setupRemotesInConfig(StoredConfig gitConfig, String originUrl) throws IOException, ConfigInvalidException { if (!Strings.isNullOrEmpty(originUrl)) { if (Strings.isNullOrEmpty(gitConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, context.getMaster(), "remote"))) { gitConfig.setString(ConfigConstants.CONFIG_BRANCH_SECTION, context.getMaster(), "remote", Constants.DEFAULT_REMOTE_NAME); } if (Strings.isNullOrEmpty(gitConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, context.getMaster(), "merge"))) { gitConfig.setString(ConfigConstants.CONFIG_BRANCH_SECTION, context.getMaster(), "merge", Constants.R_HEADS + context.getMaster()); } if (Strings.isNullOrEmpty(gitConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, context.getDevelop(), "remote"))) { gitConfig.setString(ConfigConstants.CONFIG_BRANCH_SECTION, context.getDevelop(), "remote", Constants.DEFAULT_REMOTE_NAME); } if (Strings.isNullOrEmpty(gitConfig.getString(ConfigConstants.CONFIG_BRANCH_SECTION, context.getDevelop(), "merge"))) { gitConfig.setString(ConfigConstants.CONFIG_BRANCH_SECTION, context.getDevelop(), "merge", Constants.R_HEADS + context.getDevelop()); } if (Strings.isNullOrEmpty(gitConfig.getString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, "fetch"))) { gitConfig.setString(ConfigConstants.CONFIG_REMOTE_SECTION, Constants.DEFAULT_REMOTE_NAME, "fetch", "+refs/heads/*:refs/remotes/origin/*"); } gitConfig.save(); gitConfig.load(); } }
editableConfig.load(); } catch (ConfigInvalidException e) { throw new IOException(e.getMessage());
@Override public void fixCygwinIfNeeded(JGitFlow flow) throws JGitFlowReleaseException { if(isCygwin) { getLogger().info("detected cygwin:"); try { getLogger().info(" - turning off filemode..."); StoredConfig config = flow.git().getRepository().getConfig(); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false); config.save(); config.load(); } catch (IOException e) { throw new JGitFlowReleaseException("error configuring filemode for cygwin", e); } catch (ConfigInvalidException e) { throw new JGitFlowReleaseException("error configuring filemode for cygwin", e); } getLogger().info(" - fixing maven prompter..."); prompter.setCygwinTerminal(); } }
protected void doPushNewBranchIfNeeded(JGitFlowExtension pushExtension, String branchToPush) throws GitAPIException, JGitFlowGitAPIException, JGitFlowExtensionException, RemoteBranchExistsException, IOException { if (isPush()) { enforcer().requireRemoteBranchAbsent(branchToPush); reporter.infoText(getCommandName(), "pushing new branch to origin: " + branchToPush); git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(new RefSpec(gfConfig.getDevelop()), new RefSpec(branchToPush)).call(); reporter.debugText(getCommandName(), "push complete"); git.fetch().setRemote(Constants.DEFAULT_REMOTE_NAME).call(); //setup tracking StoredConfig config = git.getRepository().getConfig(); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchToPush, ConfigConstants.CONFIG_KEY_REMOTE, Constants.DEFAULT_REMOTE_NAME); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchToPush, ConfigConstants.CONFIG_KEY_MERGE, Constants.R_HEADS + branchToPush); config.save(); try { config.load(); } catch (ConfigInvalidException e) { throw new JGitFlowGitAPIException("unable to load config", e); } runExtensionCommands(pushExtension.afterPush()); } }
protected void doPushNewBranchIfNeeded(JGitFlowExtension pushExtension, String branchToPush) throws GitAPIException, JGitFlowGitAPIException, JGitFlowExtensionException, RemoteBranchExistsException, IOException { if (isPush()) { enforcer().requireRemoteBranchAbsent(branchToPush); reporter.infoText(getCommandName(), "pushing new branch to origin: " + branchToPush); git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(new RefSpec(gfConfig.getDevelop()), new RefSpec(branchToPush)).call(); reporter.debugText(getCommandName(), "push complete"); git.fetch().setRemote(Constants.DEFAULT_REMOTE_NAME).call(); //setup tracking StoredConfig config = git.getRepository().getConfig(); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchToPush, ConfigConstants.CONFIG_KEY_REMOTE, Constants.DEFAULT_REMOTE_NAME); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchToPush, ConfigConstants.CONFIG_KEY_MERGE, Constants.R_HEADS + branchToPush); config.save(); try { config.load(); } catch (ConfigInvalidException e) { throw new JGitFlowGitAPIException("unable to load config", e); } runExtensionCommands(pushExtension.afterPush()); } }