Module: Git::Repository::Logging

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

Overview

Facade methods for querying commit history

Included by Git::Repository.

Instance Method Summary collapse

Instance Method Details

#full_log_commits(opts = {}) ⇒ Array<Hash>

Returns commits within the given revision range

Returns the parsed raw log output for each commit.

Examples:

Return commits from all refs

repo.full_log_commits(all: true).first['sha']
#=> "a1b2c3d4..."

Return commits between two revisions

repo.full_log_commits(between: ['v1.0.0', 'HEAD']).map { |c| c['sha'] }
#=> ["d4e5f6...", "a1b2c3..."]

Parameters:

  • opts (Hash) (defaults to: {})

    options for the log query

Options Hash (opts):

  • :count (Integer, nil) — default: nil

    maximum number of commits to return

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

    include commits reachable from any ref

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

    omit commits equivalent to cherry-picked commits

  • :since (String) — default: nil

    include commits newer than this date expression

  • :until (String) — default: nil

    include commits older than this date expression

  • :grep (String) — default: nil

    only include commits whose message matches this pattern

  • :author (String) — default: nil

    only include commits whose author matches this pattern

  • :between (Array<String>) — default: nil

    revision range as two commit-ish values

    When both :between and :object are provided, :between takes precedence.

  • :object (String) — default: nil

    single revision range expression for git log

    Ignored when :between is provided.

  • :path_limiter (String, Pathname, Array<String, Pathname>) — default: nil

    only include commits that impact files from the specified path(s)

  • :skip (Integer) — default: nil

    skip this many commits before output

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

    include only merge commits

Returns:

  • (Array<Hash>)

    the parsed raw log output for each commit

Raises:

  • (ArgumentError)

    if unsupported options are provided

  • (ArgumentError)

    if :count is not an Integer

  • (Git::FailedError)

    if git exits with a non-zero exit status

See Also:



74
75
76
77
78
79
80
81
82
# File 'lib/git/repository/logging.rb', line 74

def full_log_commits(opts = {})
  SharedPrivate.assert_valid_opts!(FULL_LOG_COMMITS_ALLOWED_OPTS, **opts)
  Private.validate_log_count_option!(opts)
  Private.validate_log_between_option!(opts)

  call_opts = Private.log_base_call_options(opts, skip: opts[:skip], merges: opts[:merges])
  revision_range_args = Private.log_revision_range_args(opts)
  Private.run_log_command(@execution_context, revision_range_args, call_opts)
end

#log(count = 30) ⇒ Git::Log

Returns a new Log query builder scoped to this repository

Examples:

Build a log query and execute it

results = repo.log(50).author('Alice').since('2 weeks ago').execute
results.each { |commit| puts commit.sha }

Parameters:

  • count (Integer, Symbol, nil) (defaults to: 30)

    the maximum number of commits to return, or :all / nil to return all commits; passed directly to Log#initialize

Returns:

  • (Git::Log)

    a new log query builder

See Also:



97
98
99
# File 'lib/git/repository/logging.rb', line 97

def log(count = 30)
  Git::Log.new(self, count)
end