module Transpec::Git

Constants

COMMIT_MESSAGE_FILENAME
GIT

Public Instance Methods

clean?() click to toggle source
# File lib/transpec/git.rb, line 22
def clean?
  fail_unless_inside_of_repository
  `#{GIT} status --porcelain`.empty?
end
command_available?() click to toggle source
# File lib/transpec/git.rb, line 10
def command_available?
  ENV['PATH'].split(File::PATH_SEPARATOR).any? do |path|
    git_path = File.join(path, GIT)
    File.exist?(git_path)
  end
end
fail_unless_inside_of_repository() click to toggle source
# File lib/transpec/git.rb, line 39
def fail_unless_inside_of_repository
  fail 'The current working directory is not a Git repository' unless inside_of_repository?
end
git_dir_path() click to toggle source
# File lib/transpec/git.rb, line 27
def git_dir_path
  fail_unless_inside_of_repository
  `#{GIT} rev-parse --git-dir`.chomp
end
inside_of_repository?() click to toggle source
# File lib/transpec/git.rb, line 17
def inside_of_repository?
  fail "`#{GIT}` command is not available" unless command_available?
  system("#{GIT} rev-parse --is-inside-work-tree > /dev/null 2> /dev/null")
end
write_commit_message(message) click to toggle source
# File lib/transpec/git.rb, line 32
def write_commit_message(message)
  fail_unless_inside_of_repository
  file_path = File.expand_path(File.join(git_dir_path, COMMIT_MESSAGE_FILENAME))
  File.write(file_path, message.to_s)
  file_path
end