Class: RubyGit::Status::Branch

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_git/status/branch.rb

Overview

Represents git branch information

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#aheadInteger

Number of commits ahead of upstream

Examples:

branch.ahead #=> 2

Returns:

  • (Integer)

    number of commits ahead



55
56
57
# File 'lib/ruby_git/status/branch.rb', line 55

def ahead
  @ahead
end

#behindInteger

Number of commits behind upstream

Examples:

branch.behind #=> 3

Returns:

  • (Integer)

    number of commits behind



67
68
69
# File 'lib/ruby_git/status/branch.rb', line 67

def behind
  @behind
end

#nameString?

The name of the current branch

Examples:

branch.name #=> 'main'

Returns:

  • (String, nil)

    branch name or nil if detached HEAD



19
20
21
# File 'lib/ruby_git/status/branch.rb', line 19

def name
  @name
end

#oidString

The object ID (hash) of the current commit

Examples:

branch.oid #=> 'abcdef1234567890'

Returns:

  • (String)

    commit hash



31
32
33
# File 'lib/ruby_git/status/branch.rb', line 31

def oid
  @oid
end

#upstreamString?

The name of the upstream branch

Examples:

branch.upstream #=> 'origin/main'

Returns:

  • (String, nil)

    upstream branch name or nil if no upstream



43
44
45
# File 'lib/ruby_git/status/branch.rb', line 43

def upstream
  @upstream
end

Instance Method Details

#detached?Boolean

Check if HEAD is detached

Examples:

branch.detached? #=> true

Returns:

  • (Boolean)

    true if HEAD is detached



87
88
89
# File 'lib/ruby_git/status/branch.rb', line 87

def detached?
  @name.nil?
end

#upstream?Boolean

Check if the branch has an upstream configured

Examples:

branch.upstream? #=> true

Returns:

  • (Boolean)

    true if upstream is configured



76
77
78
# File 'lib/ruby_git/status/branch.rb', line 76

def upstream?
  !@upstream.nil?
end