module Git

Public Class Methods

execute(command, msg = '') click to toggle source

Take a git command and execute Abort 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 36
def self.execute(command, msg = '')
  output = `git #{command}`

  abort "Git command failed: '#{command}'" + " #{msg}" unless $?.success?

  return output
end
log(file) 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.

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 51
def self.log(file)
  Git.execute("ls-files --error-unmatch #{file}", "File is not added in git: #{file}")
  Log.new(execute("log --pretty=format:'%an;%ae' #{file}"))
end