module JekyllGitAuthors::Git

Public Class Methods

execute(command) click to toggle source

Take a git command and execute Raise Git::ExecutionError if command didn’t execute successfully then return output of the command. Print custom message if required.

# File lib/jekyll-git-authors/git.rb, line 55
def self.execute(command)
  stdout, stderr, status = Open3.capture3("git #{command}")

  raise Git::ExecutionError.new(command, stdout, stderr) unless status.success?

  stdout
end
log(file, max_authors_count = 5) click to toggle source

Check if file is tracked with git. If it is not, exit status 1 will be returned by git. so it will be aborted by execute method. max_authors_count - maximum of returned authors

Create instance of Git::Log and pass it output from git log command return 5 last authors of a particular file %an returns author, semicolon for effortless parsing, %ae return email of author

# File lib/jekyll-git-authors/git.rb, line 71
def self.log(file, max_authors_count = 5)
  Git.execute("ls-files --error-unmatch #{file}")
  Log.new(execute("log --pretty=format:'%an;%ae' #{file}"), max_authors_count)
end