Class ReceiveCommand

java.lang.Object
org.eclipse.jgit.transport.ReceiveCommand
Direct Known Subclasses:
TrackingRefUpdate.Command

public class ReceiveCommand extends Object
A command being processed by ReceivePack.

This command instance roughly translates to the server side representation of the RemoteRefUpdate created by the client.

  • Field Details

    • oldId

      private final ObjectId oldId
    • oldSymref

      private final String oldSymref
    • newId

      private final ObjectId newId
    • newSymref

      private final String newSymref
    • name

      private final String name
    • type

      private ReceiveCommand.Type type
    • typeIsCorrect

      private boolean typeIsCorrect
    • ref

      private Ref ref
    • status

      private ReceiveCommand.Result status
    • message

      private String message
    • customRefLog

      private boolean customRefLog
    • refLogMessage

      private String refLogMessage
    • refLogIncludeResult

      private boolean refLogIncludeResult
    • forceRefLog

      private Boolean forceRefLog
  • Constructor Details

    • ReceiveCommand

      public ReceiveCommand(ObjectId oldId, ObjectId newId, String name)
      Create a new command for ReceivePack.
      Parameters:
      oldId - the expected old object id; must not be null. Use ObjectId.zeroId() to indicate a ref creation.
      newId - the new object id; must not be null. Use ObjectId.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 for ReceivePack.
      Parameters:
      oldId - the old object id; must not be null. Use ObjectId.zeroId() to indicate a ref creation.
      newId - the new object id; must not be null. Use ObjectId.zeroId() to indicate a ref deletion.
      name - name of the ref being affected.
      type - type of the command. Must be ReceiveCommand.Type.CREATE if oldId is zero, or ReceiveCommand.Type.DELETE if newId is zero.
      Since:
      2.0
    • ReceiveCommand

      private ReceiveCommand(ObjectId oldId, String newSymref, String name)
      Create a command to switch a reference from object to symbolic.
      Parameters:
      oldId - the old object id; must not be null. Use ObjectId.zeroId() to indicate a ref creation.
      newSymref - new target, must begin with "refs/". Use null to indicate a ref deletion.
      name - name of the reference to make symbolic.
      Since:
      4.10
    • ReceiveCommand

      private ReceiveCommand(String oldSymref, ObjectId newId, String name)
      Create a command to switch a reference from symbolic to object.
      Parameters:
      oldSymref - expected old target. Use null to indicate a ref creation.
      newId - the new object id; must not be null. Use ObjectId.zeroId() to indicate a ref deletion.
      name - name of the reference to convert from symbolic.
      Since:
      4.10
    • ReceiveCommand

      private ReceiveCommand(@Nullable String oldTarget, String newTarget, String name)
      Create a command to switch a symbolic reference's target.
      Parameters:
      oldTarget - expected old target. Use null to indicate a ref creation.
      newTarget - new target. Use null to indicate a ref deletion.
      name - name of the reference to make symbolic.
      Since:
      4.10
  • Method Details

    • 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 to ReceiveCommand.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 be zeroId 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 be zeroId() 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; see ReceiveCommand.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 containing BatchRefUpdate.

      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 containing BatchRefUpdate.

      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 by disableRefLog().
      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 into getNewId(). If some commits are not merged the update type is changed to ReceiveCommand.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
    • setRef

      void setRef(Ref r)
    • setType

      void setType(ReceiveCommand.Type t)
    • setTypeFastForwardUpdate

      void setTypeFastForwardUpdate()
    • setResult

      public void setResult(RefUpdate.Result r)
      Set the result of this command.
      Parameters:
      r - the new result code for this command.
    • reject

      void reject(IOException err)
    • toString

      public String toString()
      Overrides:
      toString in class Object