Class: Git::DetachedHeadInfo Private

Inherits:
Data
  • Object
show all
Defined in:
lib/git/detached_head_info.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Value object representing a detached HEAD state

When HEAD points directly to a commit rather than a branch reference, the repository is in a "detached HEAD" state. This object captures that state along with the commit SHA that HEAD points to.

This class shares a minimal interface with BranchInfo to allow polymorphic usage where appropriate:

  • short_name - returns 'HEAD'
  • target_oid - returns the commit SHA
  • to_s - returns 'HEAD'
  • detached? - returns true

Work in progress; this class is internal for now and may be made public in a future release.

Examples:

Detecting detached HEAD state

head = repo.show_current
if head.detached?
  puts "HEAD detached at #{head.target_oid[0, 7]}"
else
  puts "On branch #{head.short_name}"
end

Polymorphic usage

head = repo.show_current
puts "Checked out: #{head.short_name}"  # Works for both types
system("git log #{head.short_name}")    # Works for both types

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#target_oidString (readonly)

The commit object ID (SHA) that HEAD points to

Returns:

  • (String)

    the full 40-character object ID



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/git/detached_head_info.rb', line 44

DetachedHeadInfo = Data.define(:target_oid) do
  # @return [Boolean] always true for DetachedHeadInfo
  def detached? = true

  # @return [Boolean] always false for DetachedHeadInfo (detached HEAD always has a commit)
  def unborn? = false

  # @return [String] always 'HEAD'
  def short_name = 'HEAD'

  # @return [String] always 'HEAD'
  def to_s = 'HEAD'
end

Instance Method Details

#detached?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns always true for DetachedHeadInfo.

Returns:

  • (Boolean)

    always true for DetachedHeadInfo



46
# File 'lib/git/detached_head_info.rb', line 46

def detached? = true

#short_nameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns always 'HEAD'.

Returns:

  • (String)

    always 'HEAD'



52
# File 'lib/git/detached_head_info.rb', line 52

def short_name = 'HEAD'

#to_sString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns always 'HEAD'.

Returns:

  • (String)

    always 'HEAD'



55
# File 'lib/git/detached_head_info.rb', line 55

def to_s = 'HEAD'

#unborn?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns always false for DetachedHeadInfo (detached HEAD always has a commit).

Returns:

  • (Boolean)

    always false for DetachedHeadInfo (detached HEAD always has a commit)



49
# File 'lib/git/detached_head_info.rb', line 49

def unborn? = false