Module: Licensed::Git

Defined in:
lib/licensed/git.rb

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns whether git commands are available

Returns:

  • (Boolean)


6
7
8
# File 'lib/licensed/git.rb', line 6

def available?
  @git ||= Licensed::Shell.tool_available?("git")
end

.commit_date(sha) ⇒ Object

Returns the commit date for the provided SHA as a timestamp

sha - commit sha to retrieve date



33
34
35
36
# File 'lib/licensed/git.rb', line 33

def commit_date(sha)
  return unless available? && sha
  Licensed::Shell.execute("git", "show", "-s", "-1", "--format=%ct", sha)
end

.repository_rootObject



10
11
12
13
# File 'lib/licensed/git.rb', line 10

def repository_root
  return unless available?
  @root ||= Pathname.new(Licensed::Shell.execute("git", "rev-parse", "--show-toplevel"))
end

.version(descriptor) ⇒ Object

Returns the most recent git SHA for a file or directory or nil if SHA is not available

descriptor - file or directory to retrieve latest SHA for



19
20
21
22
23
24
25
26
27
28
# File 'lib/licensed/git.rb', line 19

def version(descriptor)
  return unless available? && descriptor

  dir = File.directory?(descriptor) ? descriptor : File.dirname(descriptor)
  file = File.directory?(descriptor) ? "." : File.basename(descriptor)

  Dir.chdir dir do
    Licensed::Shell.execute("git", "rev-list", "-1", "HEAD", "--", file)
  end
end