Class: GitBundle::Push
- Inherits:
-
Object
- Object
- GitBundle::Push
- Includes:
- Console
- Defined in:
- lib/git_bundle/push.rb
Constant Summary
Constants included from Console
Instance Method Summary collapse
-
#initialize(repositories, args) ⇒ Push
constructor
A new instance of Push.
- #invoke ⇒ Object
- #prompt_confirm ⇒ Object
Methods included from Console
#puts_attention, #puts_error, #puts_heading, #puts_prompt, #puts_repo_heading
Constructor Details
#initialize(repositories, args) ⇒ Push
Returns a new instance of Push.
5 6 7 8 |
# File 'lib/git_bundle/push.rb', line 5 def initialize(repositories, args) @repositories = repositories @args = args end |
Instance Method Details
#invoke ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/git_bundle/push.rb', line 36 def invoke @repositories.each do |repo| if repo.locked_branch != repo.branch puts_error "\nThe git revisions of #{repo.name} does not match. Are you running the correct branch?" puts_error "You are running #{repo.name} branch: #{repo.branch}" puts_error "Gemfile.lock references: #{repo.locked_branch}" return end end = @repositories.map { |repo| repo. }.uniq.join("\n\n") @repositories.reject { |repo| repo.main || repo.commits_not_pushed.empty? }.each do |repo| puts_repo_heading(repo) unless repo.push(@args) puts_error "Failed to push changes of #{repo.name}. Try pulling the latest changes or resolve conflicts first." return end end puts_repo_heading(main_repository) repo_changes = @repositories.any? { |repo| repo.revision == repo.locked_revision } build_gemfile_lock if repo_changes if main_repository.file_changed?('Gemfile.lock') main_repository.add_file('Gemfile.lock') main_repository.commit("Updated Gemfile.lock to include changes: #{}", 'Gemfile.lock') end main_repository.push(@args) end |
#prompt_confirm ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/git_bundle/push.rb', line 10 def prompt_confirm commits_to_push = false @repositories.each do |repo| commits = repo.commits_not_pushed puts_repo_heading(repo) if commits.empty? puts 'No changes.' else commits_to_push = true puts commits end end if commits_to_push puts_prompt("\nAre you sure you want to push these changes? (Y/N)") STDIN.getch.upcase == 'Y' elsif main_repository.file_changed?('Gemfile.lock') puts_prompt("\nAlthough you don't have any commits to push, your Gemfile.lock needs to be rebuilt, committed and pushed.") puts_prompt('Do you want to continue? (Y/N)') STDIN.getch.upcase == 'Y' end end |