class Git::Log


@api public
results.each { |commit| puts commit.sha }
puts “Found #{results.size} commits.”
results = log.execute
log = git.log.max_count(50).between(‘v1.0’, ‘v1.1’).author(‘Scott’)
@example Using the modern ‘execute` API
`#execute` method or the deprecated Enumerable methods.
The query is lazily executed when results are requested either via the modern
This class provides a fluent interface for building complex `git log` queries.
Builds and executes a `git log` query.

def [](index)

Deprecated:
  • Use {#execute} and call the method on the result.
def [](index)
  Git::Deprecation.warn(
    'Calling Git::Log#[] is deprecated. Call #execute and then #[] on the result object.'
  )
  run_log_if_dirty
  @commits&.[](index)
end

def all = set_option(:all, true)

def all                 = set_option(:all, true)

def author(regex) = set_option(:author, regex)

def author(regex)       = set_option(:author, regex)

def between(val1, val2 = nil) = set_option(:between, [val1, val2])

def between(val1, val2 = nil) = set_option(:between, [val1, val2])

def cherry = set_option(:cherry, true)

def cherry              = set_option(:cherry, true)

def each(&)

Deprecated:
  • Use {#execute} and call `each` on the result.
def each(&)
  Git::Deprecation.warn(
    'Calling Git::Log#each is deprecated. Call #execute and then #each on the result object.'
  )
  run_log_if_dirty
  @commits.each(&)
end

def execute

Returns:
  • (Git::Log::Result) - an object containing the log results
def execute
  run_log_if_dirty
  Result.new(@commits)
end

def first

Deprecated:
  • Use {#execute} and call the method on the result.
def first
  Git::Deprecation.warn(
    'Calling Git::Log#first is deprecated. Call #execute and then #first on the result object.'
  )
  run_log_if_dirty
  @commits&.first
end

def grep(regex) = set_option(:grep, regex)

def grep(regex)         = set_option(:grep, regex)

def initialize(base, max_count = 30)

Parameters:
  • max_count (Integer, Symbol, nil) -- the number of commits to return, or
  • base (Git::Base) -- the git repository object
def initialize(base, max_count = 30)
  @base = base
  @options = {}
  @dirty = true
  self.max_count(max_count)
end

def last

Deprecated:
  • Use {#execute} and call the method on the result.
def last
  Git::Deprecation.warn(
    'Calling Git::Log#last is deprecated. Call #execute and then #last on the result object.'
  )
  run_log_if_dirty
  @commits&.last
end

def max_count(num) = set_option(:count, num == :all ? nil : num)


Each method returns `self` to allow for chaining.
Set query options using a fluent interface.
def max_count(num)      = set_option(:count, num == :all ? nil : num)

def merges = set_option(:merges, true)

def merges              = set_option(:merges, true)

def object(objectish) = set_option(:object, objectish)

def object(objectish)   = set_option(:object, objectish)

def path(path) = set_option(:path_limiter, path)

def path(path)          = set_option(:path_limiter, path)

def run_log_if_dirty

def run_log_if_dirty
  return unless @dirty
  log_data = @base.lib.full_log_commits(@options)
  @commits = log_data.map { |c| Git::Object::Commit.new(@base, c['sha'], c) }
  @dirty = false
end

def set_option(key, value)

def set_option(key, value)
  @dirty = true
  @options[key] = value
  self
end

def since(date) = set_option(:since, date)

def since(date)         = set_option(:since, date)

def size

Deprecated:
  • Use {#execute} and call `size` on the result.
def size
  Git::Deprecation.warn(
    'Calling Git::Log#size is deprecated. Call #execute and then #size on the result object.'
  )
  run_log_if_dirty
  @commits&.size
end

def skip(num) = set_option(:skip, num)

def skip(num)           = set_option(:skip, num)

def to_s

Deprecated:
  • Use {#execute} and call `to_s` on the result.
def to_s
  Git::Deprecation.warn(
    'Calling Git::Log#to_s is deprecated. Call #execute and then #to_s on the result object.'
  )
  run_log_if_dirty
  @commits&.map(&:to_s)&.join("\n")
end

def until(date) = set_option(:until, date)

def until(date)         = set_option(:until, date)