Class: Thrust::Git
- Inherits:
-
Object
- Object
- Thrust::Git
- Defined in:
- lib/thrust/git.rb
Instance Method Summary collapse
- #checkout_file(filename) ⇒ Object
- #commit_count ⇒ Object
- #commit_summary_for_last_deploy(deployment_target) ⇒ Object
- #current_commit ⇒ Object
- #ensure_clean ⇒ Object
- #generate_notes_for_deployment(deployment_target) ⇒ Object
-
#initialize(out = $stdout, thrust_executor = Thrust::Executor.new) ⇒ Git
constructor
A new instance of Git.
- #reset ⇒ Object
Constructor Details
#initialize(out = $stdout, thrust_executor = Thrust::Executor.new) ⇒ Git
Returns a new instance of Git.
6 7 8 9 |
# File 'lib/thrust/git.rb', line 6 def initialize(out = $stdout, thrust_executor = Thrust::Executor.new) @thrust_executor = thrust_executor @out = out end |
Instance Method Details
#checkout_file(filename) ⇒ Object
28 29 30 |
# File 'lib/thrust/git.rb', line 28 def checkout_file(filename) @thrust_executor.system_or_exit("git checkout #{filename}") end |
#commit_count ⇒ Object
57 58 59 |
# File 'lib/thrust/git.rb', line 57 def commit_count @thrust_executor.capture_output_from_system("git rev-list HEAD | wc -l").strip end |
#commit_summary_for_last_deploy(deployment_target) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/thrust/git.rb', line 32 def commit_summary_for_last_deploy(deployment_target) sha_of_latest_deployed_commit = latest_deployed_commit(deployment_target) if sha_of_latest_deployed_commit "#{deployment_target}:".blue + " #{summary_for_commit(sha_of_latest_deployed_commit)}" else "#{deployment_target}:".blue + ' Never deployed' end end |
#current_commit ⇒ Object
20 21 22 |
# File 'lib/thrust/git.rb', line 20 def current_commit @thrust_executor.capture_output_from_system('git log --format=format:%h -1').strip end |
#ensure_clean ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/thrust/git.rb', line 11 def ensure_clean if ENV['IGNORE_GIT'] @out.puts 'WARNING NOT CHECKING FOR CLEAN WORKING DIRECTORY'.red else @out.puts 'Checking for clean working tree...' @thrust_executor.system_or_exit 'git diff-index --quiet HEAD' end end |
#generate_notes_for_deployment(deployment_target) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/thrust/git.rb', line 41 def generate_notes_for_deployment(deployment_target) sha_of_latest_commit = @thrust_executor.capture_output_from_system('git rev-parse HEAD').strip sha_of_latest_deployed_commit = latest_deployed_commit(deployment_target) notes = Tempfile.new('deployment_notes') if sha_of_latest_deployed_commit @thrust_executor.system_or_exit("git log --oneline #{sha_of_latest_deployed_commit}...#{sha_of_latest_commit}", notes.path) else notes.puts(summary_for_commit(sha_of_latest_commit)) notes.close end notes.path end |
#reset ⇒ Object
24 25 26 |
# File 'lib/thrust/git.rb', line 24 def reset @thrust_executor.system_or_exit('git reset --hard') end |