Class: Changelogger::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/changelogger/git.rb

Overview

Changelogger::Git wraps read-only git queries used by this gem.

Constant Summary collapse

SEP =

Separator used for pretty-format parsing

"\x01"

Class Method Summary collapse

Class Method Details

.commitsArray<Commit>

Changelogger::Git.commits -> Array<Changelogger::Commit>

Returns repository commits in chronological order (oldest-first). Uses: git log –date=short –reverse –pretty=format:‘…’

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/changelogger/git.rb', line 29

def self.commits
  format = "%H#{SEP}%h#{SEP}%ad#{SEP}%s#{SEP}%b"
  cmd = "git log --date=short --reverse --pretty=format:'#{format}'"
  out = `#{cmd}`
  out.split("\n").map do |line|
    sha, short, date, subject, body = line.split(SEP, 5)
    Commit.new(
      sha: sha,
      short: short,
      date: date,
      subject: (subject || '').strip,
      body: (body || '').strip
    )
  end
end