class Agate::Branch

Overview

Represents a git branch (a reference under refs/heads/ or refs/remotes/).

Defined in:

agate/branch.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Agate::Reference

<=>(other : Reference) : Int32 <=>, ==(other : Reference) : Bool ==, branch? : Bool branch?, log : Array(ReflogEntry) log, log? : Bool log?, name : String name, note? : Bool note?, owner : Repository owner, peel(target_type : Object::Type = Object::Type::Any) : Object peel, remote? : Bool remote?, resolve : Reference resolve, shorthand : String shorthand, symbolic_target : String | Nil symbolic_target, tag? : Bool tag?, target_id : OID target_id, target_id? : OID | Nil target_id?, type : Type type, update(target : OID, log_message : String = "") : Reference update

Constructor methods inherited from class Agate::Reference

dwim(repo : Repository, shorthand : String) : Reference dwim, lookup(repo : Repository, name : String) : Reference lookup

Class methods inherited from class Agate::Reference

dwim?(repo : Repository, shorthand : String) : Reference | Nil dwim?, lookup?(repo : Repository, name : String) : Reference | Nil lookup?, valid_name?(name : String) : Bool valid_name?

Constructor Detail

def self.lookup(repo : Repository, name : String, type : Filter = Filter::Local) : Branch #

Looks up a branch by name. Raises on failure.


[View source]

Class Method Detail

def self.lookup?(repo : Repository, name : String, type : Filter = Filter::Local) : Branch | Nil #

Looks up a branch by name, returning nil if not found.


[View source]
def self.valid_name?(name : String) : Bool #

Returns true if the given name is a valid branch name.


[View source]

Instance Method Detail

def canonical_name : String #

Returns the full reference name (e.g., "refs/heads/master").


[View source]
def checked_out? : Bool #

Returns true if this branch is checked out in any worktree.


[View source]
def head? : Bool #

Returns true if this branch is the current HEAD.


[View source]
def name : String #

Returns the short branch name (e.g., "master" instead of "refs/heads/master").


[View source]
def remote : Remote | Nil #

Returns the Remote object for a remote-tracking branch, or nil.

branch = repo.branches["origin/main"]
remote = branch.remote # => Remote("origin")

[View source]
def remote_name : String | Nil #

Returns the remote name for a remote-tracking branch, or nil.


[View source]
def upstream : Branch | Nil #

Returns the upstream branch, or nil if none is set.


[View source]
def upstream=(branch_name : String | Nil) : Nil #

Sets the upstream branch name. Pass nil to unset.


[View source]