Class ReceiveCommand
- java.lang.Object
-
- org.eclipse.jgit.transport.ReceiveCommand
-
public class ReceiveCommand extends Object
A command being processed byReceivePack
.This command instance roughly translates to the server side representation of the
RemoteRefUpdate
created by the client.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ReceiveCommand.Result
Result of the update command.static class
ReceiveCommand.Type
Type of operation requested.
-
Constructor Summary
Constructors Constructor Description ReceiveCommand(ObjectId oldId, ObjectId newId, String name)
Create a new command forReceivePack
.ReceiveCommand(ObjectId oldId, ObjectId newId, String name, ReceiveCommand.Type type)
Create a new command forReceivePack
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
abort(Iterable<ReceiveCommand> commands)
Set unprocessed commands as failed due to transaction aborted.void
disableRefLog()
Don't record this update in the ref's associated reflog.void
execute(ReceivePack rp)
Execute this command during a receive-pack session.static List<ReceiveCommand>
filter(Iterable<ReceiveCommand> in, ReceiveCommand.Result want)
Filter a collection of commands according to result.static List<ReceiveCommand>
filter(List<ReceiveCommand> commands, ReceiveCommand.Result want)
Filter a list of commands according to result.String
getMessage()
Get the message associated with a failure status.ObjectId
getNewId()
Get the requested new value for this ref.String
getNewSymref()
Get requested new target for a symbolic reference.ObjectId
getOldId()
Get the old value the client thinks the ref has.String
getOldSymref()
Get expected old target for a symbolic reference.Ref
getRef()
Get the ref, if this was advertised by the connection.String
getRefLogMessage()
Get the message to include in the reflog.String
getRefName()
Get the name of the ref being updated.ReceiveCommand.Result
getResult()
Get the current status code of this command.ReceiveCommand.Type
getType()
Get the type of this command; seeReceiveCommand.Type
.boolean
hasCustomRefLog()
Check whether this command has a custom reflog message setting that should override defaults in any containingBatchRefUpdate
.Boolean
isForceRefLog()
Check whether the reflog should be written regardless of repo defaults.boolean
isRefLogDisabled()
Check whether log has been disabled bydisableRefLog()
.boolean
isRefLogIncludingResult()
Check whether the reflog message should include the result of the update, such as fast-forward or force-update.static boolean
isTransactionAborted(ReceiveCommand cmd)
Check whether a command failed due to transaction aborted.static ReceiveCommand
link(String oldTarget, String newTarget, String name)
Create a command to switch a symbolic reference's target.static ReceiveCommand
link(ObjectId oldId, String newTarget, String name)
Create a command to switch a reference from object to symbolic.void
setForceRefLog(boolean force)
Force writing a reflog for the updated ref.void
setRefLogMessage(String msg, boolean appendStatus)
Set the message to include in the reflog.void
setResult(RefUpdate.Result r)
Set the result of this command.void
setResult(ReceiveCommand.Result s)
Set the status of this command.void
setResult(ReceiveCommand.Result s, String m)
Set the status of this command.String
toString()
static ReceiveCommand
unlink(String oldTarget, ObjectId newId, String name)
Create a command to switch a reference from symbolic to object.void
updateType(RevWalk walk)
Update the type of this command by checking for fast-forward.
-
-
-
Constructor Detail
-
ReceiveCommand
public ReceiveCommand(ObjectId oldId, ObjectId newId, String name)
Create a new command forReceivePack
.- Parameters:
oldId
- the expected old object id; must not be null. UseObjectId.zeroId()
to indicate a ref creation.newId
- the new object id; must not be null. UseObjectId.zeroId()
to indicate a ref deletion.name
- name of the ref being affected.
-
ReceiveCommand
public ReceiveCommand(ObjectId oldId, ObjectId newId, String name, ReceiveCommand.Type type)
Create a new command forReceivePack
.- Parameters:
oldId
- the old object id; must not be null. UseObjectId.zeroId()
to indicate a ref creation.newId
- the new object id; must not be null. UseObjectId.zeroId()
to indicate a ref deletion.name
- name of the ref being affected.type
- type of the command. Must beReceiveCommand.Type.CREATE
ifoldId
is zero, orReceiveCommand.Type.DELETE
ifnewId
is zero.- Since:
- 2.0
-
-
Method Detail
-
filter
public static List<ReceiveCommand> filter(Iterable<ReceiveCommand> in, ReceiveCommand.Result want)
Filter a collection of commands according to result.- Parameters:
in
- commands to filter.want
- desired status to filter by.- Returns:
- a copy of the command list containing only those commands with the desired status.
- Since:
- 4.2
-
filter
public static List<ReceiveCommand> filter(List<ReceiveCommand> commands, ReceiveCommand.Result want)
Filter a list of commands according to result.- Parameters:
commands
- commands to filter.want
- desired status to filter by.- Returns:
- a copy of the command list containing only those commands with the desired status.
- Since:
- 2.0
-
abort
public static void abort(Iterable<ReceiveCommand> commands)
Set unprocessed commands as failed due to transaction aborted.If a command is still
ReceiveCommand.Result.NOT_ATTEMPTED
it will be set toReceiveCommand.Result.REJECTED_OTHER_REASON
.- Parameters:
commands
- commands to mark as failed.- Since:
- 4.2
-
isTransactionAborted
public static boolean isTransactionAborted(ReceiveCommand cmd)
Check whether a command failed due to transaction aborted.- Parameters:
cmd
- command.- Returns:
- whether the command failed due to transaction aborted, as in
abort(Iterable)
. - Since:
- 4.9
-
link
public static ReceiveCommand link(@NonNull ObjectId oldId, @NonNull String newTarget, @NonNull String name)
Create a command to switch a reference from object to symbolic.- Parameters:
oldId
- expected oldId. May bezeroId
to create.newTarget
- new target; must begin with"refs/"
.name
- name of the reference to make symbolic.- Returns:
- command instance.
- Since:
- 4.10
-
link
public static ReceiveCommand link(@Nullable String oldTarget, @NonNull String newTarget, @NonNull String name)
Create a command to switch a symbolic reference's target.- Parameters:
oldTarget
- expected old target. May be null to create.newTarget
- new target; must begin with"refs/"
.name
- name of the reference to make symbolic.- Returns:
- command instance.
- Since:
- 4.10
-
unlink
public static ReceiveCommand unlink(@NonNull String oldTarget, @NonNull ObjectId newId, @NonNull String name)
Create a command to switch a reference from symbolic to object.- Parameters:
oldTarget
- expected old target.newId
- new object identifier. May bezeroId()
to delete.name
- name of the reference to convert from symbolic.- Returns:
- command instance.
- Since:
- 4.10
-
getOldId
public ObjectId getOldId()
Get the old value the client thinks the ref has.- Returns:
- the old value the client thinks the ref has.
-
getOldSymref
@Nullable public String getOldSymref()
Get expected old target for a symbolic reference.- Returns:
- expected old target for a symbolic reference.
- Since:
- 4.10
-
getNewId
public ObjectId getNewId()
Get the requested new value for this ref.- Returns:
- the requested new value for this ref.
-
getNewSymref
@Nullable public String getNewSymref()
Get requested new target for a symbolic reference.- Returns:
- requested new target for a symbolic reference.
- Since:
- 4.10
-
getRefName
public String getRefName()
Get the name of the ref being updated.- Returns:
- the name of the ref being updated.
-
getType
public ReceiveCommand.Type getType()
Get the type of this command; seeReceiveCommand.Type
.- Returns:
- the type of this command; see
ReceiveCommand.Type
.
-
getRef
public Ref getRef()
Get the ref, if this was advertised by the connection.- Returns:
- the ref, if this was advertised by the connection.
-
getResult
public ReceiveCommand.Result getResult()
Get the current status code of this command.- Returns:
- the current status code of this command.
-
getMessage
public String getMessage()
Get the message associated with a failure status.- Returns:
- the message associated with a failure status.
-
setRefLogMessage
public void setRefLogMessage(String msg, boolean appendStatus)
Set the message to include in the reflog.Overrides the default set by
setRefLogMessage
on any containingBatchRefUpdate
.- Parameters:
msg
- the message to describe this change. If null and appendStatus is false, the reflog will not be updated.appendStatus
- true if the status of the ref change (fast-forward or forced-update) should be appended to the user supplied message.- Since:
- 4.9
-
disableRefLog
public void disableRefLog()
Don't record this update in the ref's associated reflog.Equivalent to
setRefLogMessage(null, false)
.- Since:
- 4.9
-
setForceRefLog
public void setForceRefLog(boolean force)
Force writing a reflog for the updated ref.- Parameters:
force
- whether to force.- Since:
- 4.9
-
hasCustomRefLog
public boolean hasCustomRefLog()
Check whether this command has a custom reflog message setting that should override defaults in any containingBatchRefUpdate
.Does not take into account whether
#setForceRefLog(boolean)
has been called.- Returns:
- whether a custom reflog is set.
- Since:
- 4.9
-
isRefLogDisabled
public boolean isRefLogDisabled()
Check whether log has been disabled bydisableRefLog()
.- Returns:
- true if disabled.
- Since:
- 4.9
-
getRefLogMessage
@Nullable public String getRefLogMessage()
Get the message to include in the reflog.- Returns:
- message the caller wants to include in the reflog; null if the update should not be logged.
- Since:
- 4.9
-
isRefLogIncludingResult
public boolean isRefLogIncludingResult()
Check whether the reflog message should include the result of the update, such as fast-forward or force-update.- Returns:
- true if the message should include the result.
- Since:
- 4.9
-
isForceRefLog
@Nullable public Boolean isForceRefLog()
Check whether the reflog should be written regardless of repo defaults.- Returns:
- whether force writing is enabled;
null
if#setForceRefLog(boolean)
was never called. - Since:
- 4.9
-
setResult
public void setResult(ReceiveCommand.Result s)
Set the status of this command.- Parameters:
s
- the new status code for this command.
-
setResult
public void setResult(ReceiveCommand.Result s, String m)
Set the status of this command.- Parameters:
s
- new status code for this command.m
- optional message explaining the new status.
-
updateType
public void updateType(RevWalk walk) throws IOException
Update the type of this command by checking for fast-forward.If the command's current type is UPDATE, a merge test will be performed using the supplied RevWalk to determine if
getOldId()
is fully merged intogetNewId()
. If some commits are not merged the update type is changed toReceiveCommand.Type.UPDATE_NONFASTFORWARD
.- Parameters:
walk
- an instance to perform the merge test with. The caller must allocate and release this object.- Throws:
IOException
- either oldId or newId is not accessible in the repository used by the RevWalk. This usually indicates data corruption, and the command cannot be processed.
-
execute
public void execute(ReceivePack rp)
Execute this command during a receive-pack session.Sets the status of the command as a side effect.
- Parameters:
rp
- receive-pack session.- Since:
- 5.6
-
setResult
public void setResult(RefUpdate.Result r)
Set the result of this command.- Parameters:
r
- the new result code for this command.
-
-