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:



47
48
49
50
51
52
53
54
# File 'lib/git/fsck_result.rb', line 47

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:



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

def dangling
  @dangling
end

#missingArray<Git::FsckObject> (readonly)

Objects that are referenced but not present in the repository

Returns:



18
19
20
# File 'lib/git/fsck_result.rb', line 18

def missing
  @missing
end

#rootArray<Git::FsckObject> (readonly)

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

Returns:



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

def root
  @root
end

#taggedArray<Git::FsckObject> (readonly)

Tagged objects when --tags is used

Returns:



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

def tagged
  @tagged
end

#unreachableArray<Git::FsckObject> (readonly)

Objects not reachable from any ref

Returns:



22
23
24
# File 'lib/git/fsck_result.rb', line 22

def unreachable
  @unreachable
end

#warningsArray<Git::FsckObject> (readonly)

Objects with warnings (each includes a message)

Returns:



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

def warnings
  @warnings
end

Instance Method Details

#all_objectsArray<Git::FsckObject>

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

Examples:

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

Returns:



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

def all_objects
  dangling + missing + unreachable + warnings
end

#any_issues?Boolean

Returns true if any issues were found

Examples:

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

Returns:

  • (Boolean)


66
67
68
# File 'lib/git/fsck_result.rb', line 66

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

#countInteger

Returns the total number of issues found

Examples:

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

Returns:

  • (Integer)


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

def count
  all_objects.size
end

#empty?Boolean

Returns true if no issues were found

Examples:

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

Returns:

  • (Boolean)


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

def empty?
  !any_issues?
end

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

Returns a hash representation of the result

Examples:

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

Returns:



114
115
116
117
118
119
# File 'lib/git/fsck_result.rb', line 114

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