/** * Gets a reference to a local branch with the given name * @param git The git instance to use * @param branchName The name of the remote branch * @return A reference to the local branch or null * @throws JGitFlowIOException */ public static Ref getLocalBranch(Git git, String branchName) throws JGitFlowIOException { try { Ref ref2check = git.getRepository().getRef(branchName); Ref local = null; if (ref2check != null && ref2check.getName().startsWith(Constants.R_HEADS)) { local = ref2check; } return local; } catch (IOException e) { throw new JGitFlowIOException(e); } }
/** * Gets a reference to a local branch with the given name * * @param git The git instance to use * @param branchName The name of the remote branch * @return A reference to the local branch or null * @throws com.atlassian.jgitflow.core.exception.JGitFlowIOException */ public static Ref getLocalBranch(Git git, String branchName) throws JGitFlowIOException { try { Ref ref2check = git.getRepository().getRef(branchName); Ref local = null; if (ref2check != null && ref2check.getName().startsWith(Constants.R_HEADS)) { local = ref2check; } return local; } catch (IOException e) { throw new JGitFlowIOException(e); } }
/** * Gets a reference to a local branch with the given name * * @param git The git instance to use * @param branchName The name of the remote branch * @return A reference to the local branch or null * @throws com.atlassian.jgitflow.core.exception.JGitFlowIOException */ public static Ref getLocalBranch(Git git, String branchName) throws JGitFlowIOException { try { Ref ref2check = git.getRepository().getRef(branchName); Ref local = null; if (ref2check != null && ref2check.getName().startsWith(Constants.R_HEADS)) { local = ref2check; } return local; } catch (IOException e) { throw new JGitFlowIOException(e); } }
/** * Sets the name of the develop branch * @param branchName * @throws 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(); } catch (IOException e) { throw new JGitFlowIOException(e); } }
/** * Sets the value for a given prefix * @param prefixName * @param prefixValue * @throws 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(); } catch (IOException e) { throw new JGitFlowIOException(e); } } } }
/** * Sets the name of the master branch * @param branchName * @throws 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(); } catch (IOException 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 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); } }
/** * Gets an existing git flow project and returns a JGitFlow instance * * @param projectDir * @return * @throws com.atlassian.jgitflow.core.exception.JGitFlowIOException */ public static JGitFlow get(File projectDir) throws JGitFlowIOException { try { RepositoryBuilder rb = new RepositoryBuilder() .readEnvironment() .findGitDir(projectDir); File gitDir = rb.getGitDir(); Git gitRepo = Git.open(gitDir); GitFlowConfiguration gfConfig = new GitFlowConfiguration(gitRepo); return new JGitFlow(gitRepo, gfConfig); } catch (IOException e) { throw new JGitFlowIOException(e); } }
/** * Gets an existing git flow project and returns a JGitFlow instance * * @param projectDir * @return * @throws com.atlassian.jgitflow.core.exception.JGitFlowIOException */ public static JGitFlow get(File projectDir) throws JGitFlowIOException { try { RepositoryBuilder rb = new RepositoryBuilder() .readEnvironment() .findGitDir(projectDir); File gitDir = rb.getGitDir(); Git gitRepo = Git.open(gitDir); GitFlowConfiguration gfConfig = new GitFlowConfiguration(gitRepo); return new JGitFlow(gitRepo, gfConfig); } catch (IOException e) { throw new JGitFlowIOException(e); } }
/** * Gets the latest commit for a branch * * @param git The git instance to use * @param branchName The name of the branch to find the commit on * @return The latest commit for the branch * @throws com.atlassian.jgitflow.core.exception.JGitFlowIOException */ public static RevCommit getLatestCommit(Git git, String branchName) throws JGitFlowIOException { RevWalk walk = null; try { ObjectId branch = git.getRepository().resolve(branchName); walk = new RevWalk(git.getRepository()); walk.setRetainBody(true); return walk.parseCommit(branch); } catch (IOException e) { throw new JGitFlowIOException(e); } finally { if (null != walk) { walk.close(); } } }
/** * Gets the latest commit for a branch * @param git The git instance to use * @param branchName The name of the branch to find the commit on * @return The latest commit for the branch * @throws JGitFlowIOException */ public static RevCommit getLatestCommit(Git git, String branchName) throws JGitFlowIOException { RevWalk walk = null; try { ObjectId branch = git.getRepository().resolve(branchName); walk = new RevWalk(git.getRepository()); walk.setRetainBody(true); return walk.parseCommit(branch); } catch (IOException e) { throw new JGitFlowIOException(e); } finally { if (null != walk) { walk.release(); } } }
/** * Gets an existing git flow project and returns a JGitFlow instance * @param projectDir * @return * @throws JGitFlowIOException */ public static JGitFlow get(File projectDir) throws JGitFlowIOException { try { RepositoryBuilder rb = new RepositoryBuilder() .readEnvironment() .findGitDir(projectDir); File gitDir = rb.getGitDir(); Git gitRepo = Git.open(gitDir); GitFlowConfiguration gfConfig = new GitFlowConfiguration(gitRepo); return new JGitFlow(gitRepo, gfConfig, new JGitFlowReporter()); } catch (IOException e) { throw new JGitFlowIOException(e); } }