Class: GitBundle::Commands::Push

Inherits:
Object
  • Object
show all
Includes:
GitBundle::Console
Defined in:
lib/git_bundle/commands/push.rb

Constant Summary

Constants included from GitBundle::Console

GitBundle::Console::COLORS

Instance Method Summary collapse

Methods included from GitBundle::Console

#puts_attention, #puts_error, #puts_heading, #puts_prompt, #puts_repo_heading

Constructor Details

#initialize(repositories, args) ⇒ Push

Returns a new instance of Push.



6
7
8
9
# File 'lib/git_bundle/commands/push.rb', line 6

def initialize(repositories, args)
  @repositories = repositories
  @args = args
end

Instance Method Details

#invokeObject



11
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
# File 'lib/git_bundle/commands/push.rb', line 11

def invoke
  return false unless prompt_confirm

  lockfile = Bundler.default_lockfile.basename.to_s
  if gemfile_lock_stale?
    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

  combined_messages = @repositories.map { |repo| repo.commit_messages_not_pushed }.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 false
    end
  end

  puts_repo_heading(main_repository)
  if main_repository.file_changed?(lockfile)
    main_repository.add_file(lockfile)
    main_repository.commit("Updated Gemfile.lock to include changes: #{combined_messages}", lockfile)
  end

  unless main_repository.push(@args)
    puts_error "Failed to push changes of #{main_repository.name}.  Try pulling the latest changes or resolve conflicts first."
  end
end