org.eclipse.jgit.api
Class MergeCommand

java.lang.Object
  extended by org.eclipse.jgit.api.GitCommand<MergeResult>
      extended by org.eclipse.jgit.api.MergeCommand
All Implemented Interfaces:
Callable<MergeResult>

public class MergeCommand
extends GitCommand<MergeResult>

A class used to execute a Merge command. It has setters for all supported options and arguments of this command and a call() method to finally execute the command. Each instance of this class should only be used for one invocation of the command (means: one call to call())

See Also:
Git documentation about Merge

Nested Class Summary
static class MergeCommand.FastForwardMode
          The modes available for fast forward merges corresponding to the --ff, --no-ff and --ff-only options under branch..mergeoptions.
 
Field Summary
 
Fields inherited from class org.eclipse.jgit.api.GitCommand
repo
 
Constructor Summary
protected MergeCommand(Repository repo)
           
 
Method Summary
 MergeResult call()
          Executes the Merge command with all the options and parameters collected by the setter methods (e.g.
 MergeCommand include(AnyObjectId commit)
           
 MergeCommand include(Ref commit)
           
 MergeCommand include(String name, AnyObjectId commit)
           
 MergeCommand setFastForward(MergeCommand.FastForwardMode fastForwardMode)
          Sets the fast forward mode.
 MergeCommand setSquash(boolean squash)
          If true, will prepare the next commit in working tree and index as if a real merge happened, but do not make the commit or move the HEAD.
 MergeCommand setStrategy(MergeStrategy mergeStrategy)
           
 
Methods inherited from class org.eclipse.jgit.api.GitCommand
checkCallable, getRepository, setCallable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MergeCommand

protected MergeCommand(Repository repo)
Parameters:
repo -
Method Detail

call

public MergeResult call()
                 throws GitAPIException,
                        NoHeadException,
                        ConcurrentRefUpdateException,
                        CheckoutConflictException,
                        InvalidMergeHeadsException,
                        WrongRepositoryStateException,
                        NoMessageException
Executes the Merge command with all the options and parameters collected by the setter methods (e.g. include(Ref)) of this class. Each instance of this class should only be used for one invocation of the command. Don't call this method twice on an instance.

Specified by:
call in interface Callable<MergeResult>
Specified by:
call in class GitCommand<MergeResult>
Returns:
the result of the merge
Throws:
GitAPIException - or subclass thereof when an error occurs
NoHeadException
ConcurrentRefUpdateException
CheckoutConflictException
InvalidMergeHeadsException
WrongRepositoryStateException
NoMessageException

setStrategy

public MergeCommand setStrategy(MergeStrategy mergeStrategy)
Parameters:
mergeStrategy - the MergeStrategy to be used
Returns:
this

include

public MergeCommand include(Ref commit)
Parameters:
commit - a reference to a commit which is merged with the current head
Returns:
this

include

public MergeCommand include(AnyObjectId commit)
Parameters:
commit - the Id of a commit which is merged with the current head
Returns:
this

include

public MergeCommand include(String name,
                            AnyObjectId commit)
Parameters:
name - a name given to the commit
commit - the Id of a commit which is merged with the current head
Returns:
this

setSquash

public MergeCommand setSquash(boolean squash)
If true, will prepare the next commit in working tree and index as if a real merge happened, but do not make the commit or move the HEAD. Otherwise, perform the merge and commit the result.

In case the merge was successful but this flag was set to true a MergeResult with status MergeResult.MergeStatus.MERGED_SQUASHED or MergeResult.MergeStatus.FAST_FORWARD_SQUASHED is returned.

Parameters:
squash - whether to squash commits or not
Returns:
this
Since:
2.0

setFastForward

public MergeCommand setFastForward(MergeCommand.FastForwardMode fastForwardMode)
Sets the fast forward mode.

Parameters:
fastForwardMode - corresponds to the --ff/--no-ff/--ff-only options. --ff is the default option.
Returns:
this
Since:
2.2


Copyright © 2013. All Rights Reserved.