Class: Gitt::Commands::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/gitt/commands/log.rb

Overview

A Git log command wrapper.

Constant Summary collapse

KEY_MAP =
{
  author_email: "%ae",
  author_name: "%an",
  authored_at: "%at",
  authored_relative_at: "%ar",
  body: "%b",
  committed_at: "%ct",
  committed_relative_at: "%cr",
  committer_email: "%ce",
  committer_name: "%cn",
  encoding: "%e",
  notes: "%N",
  raw: "%B",
  sha: "%H",
  signature: "%G?",
  fingerprint: "%GK",
  fingerprint_key: "%GF",
  subject: "%s",
  trailers: "%(trailers)"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(shell: SHELL, key_map: KEY_MAP, parser: Parsers::Commit.new) ⇒ Log

Returns a new instance of Log.



32
33
34
35
36
# File 'lib/gitt/commands/log.rb', line 32

def initialize shell: SHELL, key_map: KEY_MAP, parser: Parsers::Commit.new
  @shell = shell
  @key_map = key_map
  @parser = parser
end

Instance Method Details

#callObject



38
# File 'lib/gitt/commands/log.rb', line 38

def call(*) = shell.call("log", *)

#index(*arguments) ⇒ Object



40
41
42
43
44
45
# File 'lib/gitt/commands/log.rb', line 40

def index *arguments
  arguments.prepend("--shortstat", pretty_format)
           .then { |pretty_format| call(*pretty_format) }
           .fmap { |content| String(content).scrub("?") }
           .fmap { |entries| build_records entries }
end

#uncommitted(path) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/gitt/commands/log.rb', line 47

def uncommitted path
  return Failure %(Invalid commit message path: "#{path}".) unless path.exist?

  shell.call("mktree")
       .bind { |raw_sha| shell.call "commit-tree", "-F", path.to_s, raw_sha.chomp }
       .bind { |sha| index "-1", sha.chomp }
       .fmap(&:first)
end