Class: Git::FsckResult

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

Overview

Represents the result of running git fsck

This class provides structured access to the objects found during a repository integrity check, categorized by their status.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dangling: [], missing: [], unreachable: [], warnings: [], root: [], tagged: []) ⇒ FsckResult

Create a new FsckResult

Parameters:



58
59
60
61
62
63
64
65
# File 'lib/git/fsck_result.rb', line 58

def initialize(dangling: [], missing: [], unreachable: [], warnings: [], root: [], tagged: [])
  @dangling = dangling
  @missing = missing
  @unreachable = unreachable
  @warnings = warnings
  @root = root
  @tagged = tagged
end

Instance Attribute Details

#danglingArray<Git::FsckObject> (readonly)

Objects not referenced by any other object

Returns:



15
16
17
# File 'lib/git/fsck_result.rb', line 15

def dangling
  @dangling
end

#missingArray<Git::FsckObject> (readonly)

Objects that are referenced but not present in the repository

Returns:



20
21
22
# File 'lib/git/fsck_result.rb', line 20

def missing
  @missing
end

#rootArray<Git::FsckObject> (readonly)

Root nodes (commits with no parents) when --root is used

Returns:



35
36
37
# File 'lib/git/fsck_result.rb', line 35

def root
  @root
end

#taggedArray<Git::FsckObject> (readonly)

Tagged objects when --tags is used

Returns:



40
41
42
# File 'lib/git/fsck_result.rb', line 40

def tagged
  @tagged
end

#unreachableArray<Git::FsckObject> (readonly)

Objects not reachable from any ref

Returns:



25
26
27
# File 'lib/git/fsck_result.rb', line 25

def unreachable
  @unreachable
end

#warningsArray<Git::FsckObject> (readonly)

Objects with warnings (each includes a message)

Returns:



30
31
32
# File 'lib/git/fsck_result.rb', line 30

def warnings
  @warnings
end

Instance Method Details

#all_objectsArray<Git::FsckObject>

Returns all objects from all categories (excluding informational root/tagged)

Examples:

Iterate over all objects

result = git.fsck
result.all_objects.each { |obj| puts obj.oid }

Returns:



101
102
103
# File 'lib/git/fsck_result.rb', line 101

def all_objects
  dangling + missing + unreachable + warnings
end

#any_issues?Boolean

Returns true if any issues were found

Examples:

Check for repository issues

result = git.fsck
puts "Repository has issues!" if result.any_issues?

Returns:

  • (Boolean)


77
78
79
# File 'lib/git/fsck_result.rb', line 77

def any_issues?
  [dangling, missing, unreachable, warnings].any?(&:any?)
end

#countInteger

Returns the total number of issues found

Examples:

Count all issues

result = git.fsck
puts "Found #{result.count} issues"

Returns:

  • (Integer)


113
114
115
# File 'lib/git/fsck_result.rb', line 113

def count
  all_objects.size
end

#empty?Boolean

Returns true if no issues were found

Examples:

Check if the result is empty

result = git.fsck
puts "Repository is clean" if result.empty?

Returns:

  • (Boolean)


89
90
91
# File 'lib/git/fsck_result.rb', line 89

def empty?
  !any_issues?
end

#to_hHash{Symbol => Array<Git::FsckObject>}

Returns a hash representation of the result

Examples:

Convert to a hash

result = git.fsck
result.to_h # => { dangling: [...], missing: [...], ... }

Returns:



125
126
127
128
129
130
# File 'lib/git/fsck_result.rb', line 125

def to_h
  {
    dangling: dangling, missing: missing, unreachable: unreachable,
    warnings: warnings, root: root, tagged: tagged
  }
end