Module: Transpec::Git
- Defined in:
- lib/transpec/git.rb
Constant Summary collapse
- GIT =
'git'
- COMMIT_MESSAGE_FILENAME =
'COMMIT_EDITMSG'
Class Method Summary collapse
- .clean? ⇒ Boolean
- .command_available? ⇒ Boolean
- .fail_unless_inside_of_repository ⇒ Object
- .git_dir_path ⇒ Object
- .inside_of_repository? ⇒ Boolean
- .write_commit_message(message) ⇒ Object
Class Method Details
.clean? ⇒ Boolean
22 23 24 25 |
# File 'lib/transpec/git.rb', line 22 def clean? fail_unless_inside_of_repository `#{GIT} status --porcelain`.empty? end |
.command_available? ⇒ Boolean
10 11 12 13 14 15 |
# 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 ⇒ Object
39 40 41 |
# 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 ⇒ Object
27 28 29 30 |
# 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? ⇒ Boolean
17 18 19 20 |
# 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) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/transpec/git.rb', line 32 def () fail_unless_inside_of_repository file_path = File.(File.join(git_dir_path, COMMIT_MESSAGE_FILENAME)) File.write(file_path, .to_s) file_path end |