Interface Ref

All Known Subinterfaces:
RefDirectory.LooseRef
All Known Implementing Classes:
ObjectIdRef, ObjectIdRef.PeeledNonTag, ObjectIdRef.PeeledTag, ObjectIdRef.Unpeeled, RefDirectory.LooseNonTag, RefDirectory.LoosePeeledTag, RefDirectory.LooseSymbolicRef, RefDirectory.LooseUnpeeled, SymbolicRef

public interface Ref
Pairing of a name and the ObjectId it currently has.

A ref in Git is (more or less) a variable that holds a single object identifier. The object identifier can be any valid Git object (blob, tree, commit, annotated tag, ...).

The ref name has the attributes of the ref that was asked for as well as the ref it was resolved to for symbolic refs plus the object id it points to and (for tags) the peeled target object id, i.e. the tag resolved recursively until a non-tag object is referenced.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    Location where a Ref is stored.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Update index value when a reference doesn't have one
  • Method Summary

    Modifier and Type
    Method
    Description
    Traverse target references until isSymbolic() is false.
    What this ref is called within the repository.
    Cached value of this ref.
    Cached value of ref^{} (the ref peeled to commit).
    How was this ref obtained?
    Get the reference this reference points to, or this.
    default long
    Indicator of the relative order between updates of a specific reference name.
    boolean
    Whether the Ref represents a peeled tag.
    boolean
    Test if this reference is a symbolic reference.
  • Field Details

    • UNDEFINED_UPDATE_INDEX

      static final long UNDEFINED_UPDATE_INDEX
      Update index value when a reference doesn't have one
      Since:
      5.4
      See Also:
  • Method Details

    • getName

      @NonNull String getName()
      What this ref is called within the repository.
      Returns:
      name of this ref.
    • isSymbolic

      boolean isSymbolic()
      Test if this reference is a symbolic reference.

      A symbolic reference does not have its own ObjectId value, but instead points to another Ref in the same database and always uses that other reference's value as its own.

      Returns:
      true if this is a symbolic reference; false if this reference contains its own ObjectId.
    • getLeaf

      @NonNull Ref getLeaf()
      Traverse target references until isSymbolic() is false.

      If isSymbolic() is false, returns this.

      If isSymbolic() is true, this method recursively traverses getTarget() until isSymbolic() returns false.

      This method is effectively

       return isSymbolic() ? getTarget().getLeaf() : this;
       
      Returns:
      the reference that actually stores the ObjectId value.
    • getTarget

      @NonNull Ref getTarget()
      Get the reference this reference points to, or this.

      If isSymbolic() is true this method returns the reference it directly names, which might not be the leaf reference, but could be another symbolic reference.

      If this is a leaf level reference that contains its own ObjectId,this method returns this.

      Returns:
      the target reference, or this.
    • getObjectId

      @Nullable ObjectId getObjectId()
      Cached value of this ref.
      Returns:
      the value of this ref at the last time we read it. May be null to indicate a ref that does not exist yet or a symbolic ref pointing to an unborn branch.
    • getPeeledObjectId

      @Nullable ObjectId getPeeledObjectId()
      Cached value of ref^{} (the ref peeled to commit).
      Returns:
      if this ref is an annotated tag the id of the commit (or tree or blob) that the annotated tag refers to; null if this ref does not refer to an annotated tag.
    • isPeeled

      boolean isPeeled()
      Whether the Ref represents a peeled tag.
      Returns:
      whether the Ref represents a peeled tag.
    • getStorage

      @NonNull Ref.Storage getStorage()
      How was this ref obtained?

      The current storage model of a Ref may influence how the ref must be updated or deleted from the repository.

      Returns:
      type of ref.
    • getUpdateIndex

      default long getUpdateIndex()
      Indicator of the relative order between updates of a specific reference name. A number that increases when a reference is updated.

      With symbolic references, the update index refers to updates of the symbolic reference itself. For example, if HEAD points to refs/heads/master, then the update index for exactRef("HEAD") will only increase when HEAD changes to point to another ref, regardless of how many times refs/heads/master is updated.

      Should not be used unless the RefDatabase that instantiated the ref supports versioning (see RefDatabase.hasVersioning())

      Returns:
      the update index (i.e. version) of this reference.
      Throws:
      UnsupportedOperationException - if the creator of the instance (e.g. RefDatabase) doesn't support versioning and doesn't override this method
      Since:
      5.3