module Maximus::GitHelper

Methods used for git commands @since 0.1.7

Public Instance Methods

branch() click to toggle source

Get current branch name @return [String]

# File lib/maximus/git_helper.rb, line 30
def branch
  `env -i git rev-parse --abbrev-ref HEAD`.strip!
end
commit_information(commit_sha) click to toggle source

A commit's insertions, deletions, and file names @since 0.1.7

# File lib/maximus/git_helper.rb, line 66
def commit_information(commit_sha)
  # Start after the commit message
  `git -C #{@config.working_dir} log --numstat --oneline #{commit_sha}`.split("\n")[1..-1]
end
files_by_sha(commit_sha) click to toggle source

Grab files by sha @since 0.1.7

# File lib/maximus/git_helper.rb, line 54
def files_by_sha(commit_sha)
  `git -C #{@config.working_dir} show --pretty="format:" --name-only #{commit_sha}`
end
first_commit() click to toggle source

Find first commit @since 0.1.5 @return [String]

# File lib/maximus/git_helper.rb, line 9
def first_commit
  `git -C #{@config.working_dir} rev-list --max-parents=0 HEAD`.strip!
end
head_sha() click to toggle source

Get last commit on current branch @return [String] sha

# File lib/maximus/git_helper.rb, line 24
def head_sha
  @g.object('HEAD').sha
end
lines_by_sha(commit_sha) click to toggle source

Retrieve insertions by commit with a custom script @since 0.1.7 @return [Array]

# File lib/maximus/git_helper.rb, line 74
def lines_by_sha(commit_sha)
  `#{File.join(File.dirname(__FILE__), 'reporter', 'git-lines.sh')} #{@config.working_dir} #{commit_sha}`.split("\n")
end
master_commit_sha() click to toggle source

Get last commit sha on the master branch @return [String]

# File lib/maximus/git_helper.rb, line 36
def master_commit_sha
  @g.branches[:master].blank? ? head_sha : @g.branches[:master].gcommit.sha
end
previous_commit(current_commit = head_sha, previous_by = 1) click to toggle source

Get commit before current @since 0.1.5 @param current_commit [String] (head_sha) commit to start at @param previous_by [Integer] (1) commit n commits ago @return [String]

# File lib/maximus/git_helper.rb, line 18
def previous_commit(current_commit = head_sha, previous_by = 1)
  `git -C #{@config.working_dir} rev-list --max-count=#{previous_by + 1} #{current_commit} --reverse | head -n1`.strip!
end
remote() click to toggle source

Get remote URL @return [String, nil] nil returns if remotes is blank

# File lib/maximus/git_helper.rb, line 42
def remote
  @g.remotes.first.url unless @g.remotes.blank?
end
sha_range(sha1, sha2) click to toggle source

Retrieve list of shas between two commits @since 0.1.7

# File lib/maximus/git_helper.rb, line 60
def sha_range(sha1, sha2)
  `git -C #{@config.working_dir} rev-list #{sha1}..#{sha2} --no-merges`
end
working_copy_files() click to toggle source

Return file names of working copy files @since 0.1.7

# File lib/maximus/git_helper.rb, line 48
def working_copy_files
  `git -C #{@config.working_dir} diff --name-only`
end