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; } }
@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()); }
.setName("master") .setStartPoint("origin/master") .setForce(true) .call();
.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); } } } }
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); } } } }
command.setName(name); if (startCommit != null) command.setStartPoint(startCommit); else command.setStartPoint(startPoint); if (upstreamMode != null) command.setUpstreamMode(upstreamMode);
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 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 Bundle createBundle(String name) throws IOException, InvalidRefNameException, RefNotFoundException, RefAlreadyExistsException { Ref templateBranch = git.getRepository().getRef(TEMPLATE_BRANCH); Preconditions.checkNotNull(templateBranch, "'%s' branch not found", TEMPLATE_BRANCH); RevCommit templateCommit = GitUtils.getCommit(git.getRepository(), templateBranch); git.branchCreate() .setName(name) .setStartPoint(templateCommit) .call(); return getBundle(name); }
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); } }
/** * 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(); } }
@Override public Void call() { try { git.branchCreate() .setName(branchName) .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM) .setStartPoint("origin/" + branchName) .setForce(true) .call(); git.checkout().setName(branchName).call(); } catch (final GitAPIException e) { LOGGER.error("Unable to create/checkout branch " + branchName, e); } return null; } });
private void updateBranch(final String targetBranchName, final org.eclipse.jgit.api.Git git, final ObjectId commitId) throws Exception { git.branchCreate() .setName(targetBranchName) .setStartPoint(commitId.name()) .setForce(true) .call(); }
private Ref branch(Git origin, String source, String target) throws Exception { final Repository repo = origin.getRepository(); return org.eclipse.jgit.api.Git.wrap(repo) .branchCreate() .setName(target) .setStartPoint(source) .call(); }
private Ref branch(Git origin, String source, String target) throws Exception { final Repository repo = origin.getRepository(); return org.eclipse.jgit.api.Git.wrap(repo) .branchCreate() .setName(target) .setStartPoint(source) .call(); }
private void updateBranch(final String targetBranchName, final org.eclipse.jgit.api.Git git, final ObjectId commitId) throws Exception { git.branchCreate() .setName(targetBranchName) .setStartPoint(commitId.name()) .setForce(true) .call(); }
public void checkoutFromRemote(String remoteBranchName, String branchName) throws GitAPIException, JGitInternalException, StopTaskException { mRepo.getGit().checkout().setCreateBranch(true).setName(branchName) .setStartPoint(remoteBranchName).call(); mRepo.getGit() .branchCreate() .setUpstreamMode( CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM) .setStartPoint(remoteBranchName).setName(branchName) .setForce(true).call(); } }
public void checkoutFromRemote(String remoteBranchName, String branchName) throws GitAPIException, JGitInternalException, StopTaskException { mRepo.getGit().checkout().setCreateBranch(true).setName(branchName) .setStartPoint(remoteBranchName).call(); mRepo.getGit() .branchCreate() .setUpstreamMode( CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM) .setStartPoint(remoteBranchName).setName(branchName) .setForce(true).call(); } }