Class: Thrust::Git
- Inherits:
-
Object
- Object
- Thrust::Git
- Defined in:
- lib/thrust/git.rb
Instance Method Summary collapse
- #checkout_file(filename) ⇒ Object
- #checkout_tag(tag) ⇒ Object
- #commit_count ⇒ Object
- #commit_summary_for_last_deploy(deployment_target) ⇒ Object
- #create_tag(tag_name) ⇒ 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
Instance Method Details
#checkout_file(filename) ⇒ Object
34 35 36 |
# File 'lib/thrust/git.rb', line 34 def checkout_file(filename) @thrust_executor.system_or_exit("git checkout #{filename}") end |
#checkout_tag(tag) ⇒ Object
24 25 26 27 |
# File 'lib/thrust/git.rb', line 24 def checkout_tag(tag) tag_sha = latest_commit_with_tag(tag) @thrust_executor.system_or_exit("git checkout #{tag_sha}") end |
#commit_count ⇒ Object
63 64 65 |
# File 'lib/thrust/git.rb', line 63 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
38 39 40 41 42 43 44 45 |
# File 'lib/thrust/git.rb', line 38 def commit_summary_for_last_deploy(deployment_target) sha_of_latest_deployed_commit = latest_commit_with_tag(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 |
#create_tag(tag_name) ⇒ Object
67 68 69 |
# File 'lib/thrust/git.rb', line 67 def create_tag(tag_name) @thrust_executor.system_or_exit("autotag create #{tag_name}") 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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/thrust/git.rb', line 47 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_commit_with_tag(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
29 30 31 32 |
# File 'lib/thrust/git.rb', line 29 def reset @thrust_executor.system_or_exit('git reset --hard') @thrust_executor.system_or_exit('git checkout master') end |