Package org.eclipse.jgit.api
Class CreateBranchCommand
- java.lang.Object
-
- org.eclipse.jgit.api.GitCommand<Ref>
-
- org.eclipse.jgit.api.CreateBranchCommand
-
- All Implemented Interfaces:
java.util.concurrent.Callable<Ref>
public class CreateBranchCommand extends GitCommand<Ref>
Used to create a local branch.- See Also:
- Git documentation about Branch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CreateBranchCommand.SetupUpstreamMode
The modes available for setting up the upstream configuration (corresponding to the --set-upstream, --track, --no-track options
-
Field Summary
Fields Modifier and Type Field Description private boolean
force
private java.lang.String
name
private RevCommit
startCommit
private java.lang.String
startPoint
private CreateBranchCommand.SetupUpstreamMode
upstreamMode
-
Fields inherited from class org.eclipse.jgit.api.GitCommand
repo
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CreateBranchCommand(Repository repo)
Constructor for CreateBranchCommand
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Ref
call()
private ObjectId
getStartPointObjectId()
private java.lang.String
getStartPointOrHead()
static boolean
isValidBranchName(java.lang.String branchName)
Check if the given branch name is validprivate void
processOptions()
CreateBranchCommand
setForce(boolean force)
Set whether to create the branch forcefullyCreateBranchCommand
setName(java.lang.String name)
Set the name of the new branchCreateBranchCommand
setStartPoint(java.lang.String startPoint)
Set the start pointCreateBranchCommand
setStartPoint(RevCommit startPoint)
Set the start pointCreateBranchCommand
setUpstreamMode(CreateBranchCommand.SetupUpstreamMode mode)
Set the upstream mode-
Methods inherited from class org.eclipse.jgit.api.GitCommand
checkCallable, getRepository, setCallable
-
-
-
-
Field Detail
-
name
private java.lang.String name
-
force
private boolean force
-
upstreamMode
private CreateBranchCommand.SetupUpstreamMode upstreamMode
-
startPoint
private java.lang.String startPoint
-
startCommit
private RevCommit startCommit
-
-
Constructor Detail
-
CreateBranchCommand
protected CreateBranchCommand(Repository repo)
Constructor for CreateBranchCommand- Parameters:
repo
- theRepository
-
-
Method Detail
-
call
public Ref call() throws GitAPIException, RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException
Execute the command
- Specified by:
call
in interfacejava.util.concurrent.Callable<Ref>
- Specified by:
call
in classGitCommand<Ref>
- Throws:
GitAPIException
RefAlreadyExistsException
RefNotFoundException
InvalidRefNameException
-
getStartPointObjectId
private ObjectId getStartPointObjectId() throws AmbiguousObjectException, RefNotFoundException, java.io.IOException
- Throws:
AmbiguousObjectException
RefNotFoundException
java.io.IOException
-
getStartPointOrHead
private java.lang.String getStartPointOrHead()
-
processOptions
private void processOptions() throws InvalidRefNameException
- Throws:
InvalidRefNameException
-
isValidBranchName
public static boolean isValidBranchName(java.lang.String branchName)
Check if the given branch name is valid- Parameters:
branchName
- branch name to check- Returns:
true
if the branch name is valid- Since:
- 5.0
-
setName
public CreateBranchCommand setName(java.lang.String name)
Set the name of the new branch- Parameters:
name
- the name of the new branch- Returns:
- this instance
-
setForce
public CreateBranchCommand setForce(boolean force)
Set whether to create the branch forcefully- Parameters:
force
- iftrue
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- Returns:
- this instance
-
setStartPoint
public CreateBranchCommand setStartPoint(java.lang.String startPoint)
Set the start point- Parameters:
startPoint
- corresponds to the start-point option; ifnull
, the current HEAD will be used- Returns:
- this instance
-
setStartPoint
public CreateBranchCommand setStartPoint(RevCommit startPoint)
Set the start point- Parameters:
startPoint
- corresponds to the start-point option; ifnull
, the current HEAD will be used- Returns:
- this instance
-
setUpstreamMode
public CreateBranchCommand setUpstreamMode(CreateBranchCommand.SetupUpstreamMode mode)
Set the upstream mode- Parameters:
mode
- corresponds to the --track/--no-track/--set-upstream options; may benull
- Returns:
- this instance
-
-