Class: GitBundle::Commands::Push
- Inherits:
-
Object
- Object
- GitBundle::Commands::Push
- Includes:
- GitBundle::Console, Shell
- Defined in:
- lib/git_bundle/commands/push.rb
Constant Summary
Constants included from GitBundle::Console
Instance Method Summary collapse
-
#initialize(project, args) ⇒ Push
constructor
A new instance of Push.
- #invoke ⇒ Object
Methods included from Shell
#execute, #execute_live, #execute_pipe
Methods included from GitBundle::Console
#clear_line, #parallel, #puts_attention, #puts_error, #puts_heading, #puts_prompt, #puts_repo_heading, #puts_repo_heading_switch, #puts_stay_on_line, #puts_wait_line
Constructor Details
#initialize(project, args) ⇒ Push
Returns a new instance of Push.
7 8 9 10 |
# File 'lib/git_bundle/commands/push.rb', line 7 def initialize(project, args) @project = project @args = args end |
Instance Method Details
#invoke ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 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 66 |
# File 'lib/git_bundle/commands/push.rb', line 12 def invoke @project.load_dependant_repositories return false unless prompt_confirm main_repository = @project.main_repository lockfile = Bundler.default_lockfile.basename.to_s stale_repos = @project.repositories.select { |repo| !repo.main && repo.stale? } = stale_repos.map do |repo| repo.upstream_branch_exists? ? "#{repo.name}(#{repo.stale_commits_count})" : "#{repo.name}(new branch)" end.join(', ') stale_commits_description = '' stale_repos.select(&:upstream_branch_exists?).each do |repo| stale_commits_description << "== #{repo.name} ==\n" stale_commits_description << repo.stale_commits stale_commits_description << "\n\n" end if stale_repos.any? puts "Local gems were updated. Building new #{lockfile} with bundle install." unless build_gemfile_lock puts_error 'Bundle install failed. Please run it manually before trying to push changes.' return false end end if main_repository.file_changed?(lockfile) main_repository.add_file(lockfile) if .empty? = 'Updated Gemfile.lock.' else = "Gemfile.lock includes new commits of: #{}." end main_repository.commit_with_description(, stale_commits_description, lockfile) puts end @project.dependant_repositories.select { |repo| repo.commits_not_pushed? }.each do |repo| puts_repo_heading(repo) create_upstream = !repo.upstream_branch_exists? unless repo.push(@args, create_upstream: create_upstream) puts_error "Failed to push changes of #{repo.name}. Try pulling the latest changes or resolve conflicts first." return false end end puts_repo_heading(main_repository) create_upstream = !main_repository.upstream_branch_exists? unless main_repository.push(@args, create_upstream: create_upstream) puts_error "Failed to push changes of #{main_repository.name}. Try pulling the latest changes or resolve conflicts first." end end |