List of usage examples for org.eclipse.jgit.api CreateBranchCommand setForce
public CreateBranchCommand setForce(boolean force)
From source file:com.microsoft.gittf.core.util.TfsBranchUtil.java
License:Open Source License
/** * //from w w w . ja va 2s . co m * Creates a remote tracking ref for tfs. If the repo is bare a regular * branch is created too. * * @param repository * @param startPoint * @throws RefAlreadyExistsException * @throws RefNotFoundException * @throws InvalidRefNameException * @throws GitAPIException * @throws IOException */ public static void create(Repository repository, String startPoint) throws RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException, GitAPIException, IOException { if (repository.isBare()) { CreateBranchCommand createBranch = new Git(repository).branchCreate(); createBranch.setName(GitTFConstants.GIT_TF_BRANCHNAME); createBranch.setForce(true); if (startPoint != null && startPoint.length() > 0) { createBranch.setStartPoint(startPoint); } createBranch.call(); } TfsRemoteReferenceUpdate remoteRefUpdate = new TfsRemoteReferenceUpdate(repository, startPoint); remoteRefUpdate.update(); }
From source file:org.ajoberstar.gradle.git.tasks.GitBranchCreate.java
License:Apache License
/** * Execute the creation or update of the branch. */// w w w.j a v a 2s. c o m @TaskAction void branchCreate() { CreateBranchCommand cmd = getGit().branchCreate(); cmd.setName(getBranchName()); cmd.setStartPoint(getStartPoint()); cmd.setForce(getForce()); if (getMode() != null) { switch (getMode()) { case NO_TRACK: cmd.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.NOTRACK); break; case TRACK: cmd.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK); break; case SET_UPSTREAM: cmd.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM); break; default: throw new AssertionError("Illegal mode: " + getMode()); } } try { cmd.call(); } catch (InvalidRefNameException e) { throw new GradleException("Invalid branch name: " + getName(), e); } catch (RefNotFoundException e) { throw new GradleException("Can't find start point: " + getStartPoint(), e); } catch (RefAlreadyExistsException e) { throw new GradleException("Branch " + getName() + " already exists. Use force=true to modify.", e); } catch (GitAPIException e) { throw new GradleException("Problem creating or updating branch " + getName(), e); } }
From source file:org.mule.module.git.GitConnector.java
License:Open Source License
/** * Create a local branch// ww w . ja va 2 s . c o m * * {@sample.xml ../../../doc/mule-module-git.xml.sample git:create-branch} * * @param branchName Name of the new branch * @param force If true and the branch with the given name already exists, the start-point of an existing branch will be set to a new start-point; if false, the existing branch will not be changed. * @param startPoint The new branch head will point to this commit. It may be given as a branch name, a commit-id, or a tag. If this option is omitted, the current HEAD will be used instead. * @param overrideDirectory Name of the directory to use for git repository */ @Processor public void createBranch(String branchName, @Optional @Default("false") boolean force, @Optional @Default("HEAD") String startPoint, @Optional String overrideDirectory) { try { Git git = new Git(getGitRepo(overrideDirectory)); CreateBranchCommand createBranch = git.branchCreate(); createBranch.setName(branchName); createBranch.setForce(force); createBranch.setStartPoint(startPoint); createBranch.call(); } catch (Exception e) { throw new RuntimeException("Unable to create branch " + branchName, e); } }