@Signature public Memory branchCreate(String name, ArrayMemory settings) throws GitAPIException { CreateBranchCommand command = getWrappedObject().branchCreate(); command.setName(name); if (settings != null && settings.isNotNull()) { Memory startPoint = settings.valueOfIndex("startPoint"); if (startPoint.isNotNull()) { command.setStartPoint(startPoint.toString()); } command.setForce(settings.valueOfIndex("force").toBoolean()); Memory upstreamMode = settings.valueOfIndex("upstreamMode"); if (upstreamMode.isNotNull()) { command.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.valueOf(upstreamMode.toString())); } } return GitUtils.valueOf(command.call()); }
void createBranch(String branchName, RevCommit revCommit) throws GitAPIException { try { git.branchCreate().setName(branchName).setStartPoint(revCommit).call(); } catch (GitAPIException e) { LOGGER.error("[CONFIG_MERGE] Failed to create branch {} at revision {}", branchName, revCommit.getId(), e); throw e; } }
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { if(repository.exactRef("refs/heads/testbranch") == null) { // first we need to ensure that the remote branch is visible locally Ref ref = git.branchCreate().setName("testbranch").setStartPoint("origin/testbranch").call(); System.out.println("Created local testbranch with ref: " + ref); } // the diff works on TreeIterators, we prepare two for the two branches AbstractTreeIterator oldTreeParser = prepareTreeParser(repository, "refs/heads/testbranch"); AbstractTreeIterator newTreeParser = prepareTreeParser(repository, "refs/heads/master"); // then the procelain diff-command returns a list of diff entries List<DiffEntry> diff = git.diff().setOldTree(oldTreeParser).setNewTree(newTreeParser).call(); for (DiffEntry entry : diff) { System.out.println("Entry: " + entry); } } } }
try (Git git = new Git(repository)) { git.branchCreate() .setName("master") .setStartPoint("origin/master") .setForce(true) .call();
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { if(repository.exactRef("refs/heads/testbranch") == null) { // first we need to ensure that the remote branch is visible locally Ref ref = git.branchCreate().setName("testbranch").setStartPoint("origin/testbranch").call(); System.out.println("Created local testbranch with ref: " + ref); } // the diff works on TreeIterators, we prepare two for the two branches AbstractTreeIterator oldTreeParser = prepareTreeParser(repository, "refs/heads/testbranch"); AbstractTreeIterator newTreeParser = prepareTreeParser(repository, "refs/heads/master"); // then the procelain diff-command returns a list of diff entries List<DiffEntry> diff = git.diff().setOldTree(oldTreeParser).setNewTree(newTreeParser).call(); for (DiffEntry entry : diff) { System.out.println("Entry: " + entry); } } } }
try (Git git = new Git(repository)) { git.branchCreate() .setName("master") .setStartPoint("origin/master") .setForce(true) .call();
public static void createBranch(final Git git, final String source, final String target) { try { git.branchCreate().setName(target).setStartPoint(source).call(); } catch (GitAPIException e) { throw new RuntimeException(e); } }
public Ref createBranch(Git git, String branchName) throws GitAPIException { return git.branchCreate() .setName(branchName) .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM) .setStartPoint("origin/" + branchName) .setForce(true) .call(); }
public static void createBranch( final Git git, final String source, final String target ) { try { git.branchCreate().setName( target ).setStartPoint( source ).call(); } catch ( GitAPIException e ) { throw new RuntimeException( e ); } }
try (Git git = new Git(repo)) { CreateBranchCommand command = git.branchCreate(); command.setName(name); if (startCommit != null) command.setStartPoint(startCommit); else command.setStartPoint(startPoint); if (upstreamMode != null) command.setUpstreamMode(upstreamMode); command.call();
@Override public String createBranch(String commitId, String branchName) { Ref result = null; CreateBranchCommand branchCreate = _git.branchCreate(); branchCreate.setName(branchName); branchCreate.setStartPoint(commitId); try { result = branchCreate.call(); } catch (Throwable e) { throw new RuntimeException(String.format( "Failed creating branch: %s for commit [%s]", branchName, commitId), e); } return result.getName(); }
/** * Create a local branch for remote tracking if it doesn't exist already. */ protected void createBranchIfNeeded(String branch) throws Exception { fetch(); // in case the branch is not known locally if (localRepo.findRef(branch) == null) { git.branchCreate() .setName(branch) .setUpstreamMode(SetupUpstreamMode.TRACK) .setStartPoint("origin/" + branch) .call(); } }
public void createBranch(String branchName, String branchRevision) { try { CreateBranchCommand command = git().branchCreate(); command.setName(branchName); RevCommit commit = getRevCommit(branchRevision); command.setStartPoint(getRevCommit(branchRevision)); command.call(); cacheObjectId(GitUtils.branch2ref(branchName), commit); } catch (GitAPIException e) { throw new RuntimeException(e); } }