class Vara::GitInspector
Attributes
repo_path[R]
Public Class Methods
current_revision(repo_path)
click to toggle source
@param repo_path
[String] Path to the root of the repository to inspect @return [String] The SHA of the current git revision
# File lib/vara/git_inspector.rb, line 5 def self.current_revision(repo_path) new(repo_path).current_revision end
git_repo?(repo_path)
click to toggle source
@param repo_path
[String] Path to the root of the repository to inspect @return [Boolean]
# File lib/vara/git_inspector.rb, line 11 def self.git_repo?(repo_path) system("cd #{repo_path} && git rev-parse --is-inside-work-tree") end
new(repo_path)
click to toggle source
@param repo_path
[String] Path to the root of the repository to inspect
# File lib/vara/git_inspector.rb, line 16 def initialize(repo_path) raise "The directory #{repo_path} must be a git repo" unless self.class.git_repo?(repo_path) @repo_path = repo_path end
Public Instance Methods
commit_count()
click to toggle source
@return [Integer] The number of commits on this git branch
# File lib/vara/git_inspector.rb, line 28 def commit_count count = `cd #{repo_path} && git rev-list HEAD | wc -l` Integer(count) end
current_revision()
click to toggle source
@return [String] The SHA of the current git revision
# File lib/vara/git_inspector.rb, line 22 def current_revision revision = `cd #{repo_path} && git rev-list --max-count=1 HEAD`.chomp [revision, dirty_suffix].join('') end
short_sha()
click to toggle source
@return [String] The abbreviated SHA of the current git revision
# File lib/vara/git_inspector.rb, line 34 def short_sha sha = `cd #{repo_path} && git rev-parse --short HEAD`.chomp [sha, dirty_suffix].join('') end
Private Instance Methods
dirty?()
click to toggle source
# File lib/vara/git_inspector.rb, line 43 def dirty? # inspired by http://stackoverflow.com/a/5737794 `cd #{repo_path} && test -n "$(git status --porcelain)"` $?.success? end
dirty_suffix()
click to toggle source
# File lib/vara/git_inspector.rb, line 49 def dirty_suffix if dirty? '.dirty' else '' end end