Module: Git::Repository::Inspecting

Included in:
Git::Repository
Defined in:
lib/git/repository/inspecting.rb

Overview

Facade methods for read-only repository inspection operations

These methods report on the contents and integrity of the repository.

Included by Git::Repository.

Instance Method Summary collapse

Instance Method Details

#fsck(*objects, **options) ⇒ Git::FsckResult

Verify the connectivity and validity of the objects in the database

Runs git fsck and returns the categorized objects it flags. Progress output is always suppressed (--no-progress) so that stdout contains only the machine-parsable findings.

Returns the objects flagged by fsck, categorized by status.

Examples:

Check repository integrity

result = repo.fsck
result.dangling.each { |obj| puts "#{obj.type}: #{obj.oid}" }

Check if the repository is clean

repo.fsck.empty? #=> true

List root commits

repo.fsck(root: true).root.each { |obj| puts obj.oid }

Check specific objects

repo.fsck('abc1234', 'def5678')

Parameters:

  • objects (Array<String>)

    specific objects to treat as heads for the unreachability trace

    When none are given, git fsck defaults to the index file, all refs, and all reflogs.

  • options (Hash)

    options for the fsck command

Options Hash (**options):

  • :tags (Boolean, nil) — default: nil

    report tags

  • :root (Boolean, nil) — default: nil

    report root nodes

  • :unreachable (Boolean, nil) — default: nil

    print objects that exist but are not reachable from any reference node

  • :cache (Boolean, nil) — default: nil

    consider objects recorded in the index as head nodes for reachability

  • :no_reflogs (Boolean, nil) — default: nil

    do not consider commits referenced only by reflogs to be reachable

  • :full (Boolean, nil) — default: nil

    also check alternate object pools and packed archives, not just the local store

  • :no_full (Boolean, nil) — default: nil

    skip alternate object pools and packed archives

  • :strict (Boolean, nil) — default: nil

    enable stricter checking

  • :verbose (Boolean, nil) — default: nil

    be chatty

  • :lost_found (Boolean, nil) — default: nil

    write dangling objects into .git/lost-found

    This modifies the repository by creating files.

  • :dangling (Boolean, nil) — default: nil

    print dangling objects

  • :no_dangling (Boolean, nil) — default: nil

    suppress dangling object reporting

  • :connectivity_only (Boolean, nil) — default: nil

    check only connectivity; faster but does not validate blob content

  • :name_objects (Boolean, nil) — default: nil

    show the name of each reachable object alongside its identifier

  • :no_name_objects (Boolean, nil) — default: nil

    suppress object name display

  • :references (Boolean, nil) — default: nil

    check reference database consistency

  • :no_references (Boolean, nil) — default: nil

    skip reference checking

Returns:

Raises:

  • (ArgumentError)

    when unsupported options are provided

  • (Git::FailedError)

    when git exits outside the allowed range (exit code > 7)



146
147
148
149
150
# File 'lib/git/repository/inspecting.rb', line 146

def fsck(*objects, **)
  SharedPrivate.assert_valid_opts!(FSCK_ALLOWED_OPTS, **)
  result = Git::Commands::Fsck.new(@execution_context).call(*objects, **, no_progress: true)
  Git::Parsers::Fsck.parse(result.stdout)
end

#show(objectish = nil, path = nil) ⇒ String

Show a single git object (a commit, tag, tree, or blob)

Examples:

Show the HEAD commit

repo.show

Show a specific commit

repo.show('HEAD~1')

Show the contents of a file at a revision

repo.show('HEAD', 'README.md')

Parameters:

  • objectish (String, nil) (defaults to: nil)

    the object to show; a ref, SHA, or objectish:path expression

    Defaults to HEAD when nil.

  • path (String, nil) (defaults to: nil)

    the file whose contents to show at objectish, when given

    Combined with objectish as objectish:path. When objectish is nil and path is given, HEAD is used as the objectish, so show(nil, 'README.md') resolves to HEAD:README.md.

Returns:

  • (String)

    git's stdout from the show, with trailing newlines preserved

Raises:



47
48
49
50
# File 'lib/git/repository/inspecting.rb', line 47

def show(objectish = nil, path = nil)
  object = path ? "#{objectish || 'HEAD'}:#{path}" : objectish
  Git::Commands::Show.new(@execution_context).call(*[object].compact).stdout
end