class Git::Log

object that holds the last X commits on given branch

Public Class Methods

new(base, count = 30) click to toggle source
# File lib/git/log.rb, line 7
def initialize(base, count = 30)
  dirty_log
  @base = base
  @count = count
end

Public Instance Methods

[](index) click to toggle source
# File lib/git/log.rb, line 100
def [](index)
  check_log
  @commits[index] rescue nil
end
all() click to toggle source
# File lib/git/log.rb, line 13
def all
  dirty_log
  @all = true
  self
end
author(regex) click to toggle source
# File lib/git/log.rb, line 25
def author(regex)
  dirty_log
  @author = regex
  return self
end
between(sha1, sha2 = nil) click to toggle source
# File lib/git/log.rb, line 61
def between(sha1, sha2 = nil)
  dirty_log
  @between = [sha1, sha2]
  return self
end
cherry() click to toggle source
# File lib/git/log.rb, line 67
def cherry
  dirty_log
  @cherry = true
  return self
end
each(&block) click to toggle source
# File lib/git/log.rb, line 85
def each(&block)
  check_log
  @commits.each(&block)
end
first() click to toggle source
# File lib/git/log.rb, line 90
def first
  check_log
  @commits.first rescue nil
end
grep(regex) click to toggle source
# File lib/git/log.rb, line 31
def grep(regex)
  dirty_log
  @grep = regex
  return self
end
last() click to toggle source
# File lib/git/log.rb, line 95
def last
  check_log
  @commits.last rescue nil
end
object(objectish) click to toggle source
# File lib/git/log.rb, line 19
def object(objectish)
  dirty_log
  @object = objectish
  return self
end
path(path) click to toggle source
# File lib/git/log.rb, line 37
def path(path)
  dirty_log
  @path = path
  return self
end
since(date) click to toggle source
# File lib/git/log.rb, line 49
def since(date)
  dirty_log
  @since = date
  return self
end
size() click to toggle source

forces git log to run

# File lib/git/log.rb, line 80
def size
  check_log
  @commits.size rescue nil
end
skip(num) click to toggle source
# File lib/git/log.rb, line 43
def skip(num)
  dirty_log
  @skip = num
  return self
end
to_s() click to toggle source
# File lib/git/log.rb, line 73
def to_s
  self.map { |c| c.to_s }.join("\n")
end
until(date) click to toggle source
# File lib/git/log.rb, line 55
def until(date)
  dirty_log
  @until = date
  return self
end

Private Instance Methods

check_log() click to toggle source
# File lib/git/log.rb, line 112
def check_log
  if @dirty_flag
    run_log
    @dirty_flag = false
  end
end
dirty_log() click to toggle source
# File lib/git/log.rb, line 108
def dirty_log
  @dirty_flag = true
end
run_log() click to toggle source

actually run the ‘git log’ command

# File lib/git/log.rb, line 120
def run_log
  log = @base.lib.full_log_commits(
    count: @count, all: @all, object: @object, path_limiter: @path, since: @since,
    author: @author, grep: @grep, skip: @skip, until: @until, between: @between,
    cherry: @cherry
  )
  @commits = log.map { |c| Git::Object::Commit.new(@base, c['sha'], c) }
end