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

#clear_line, #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
42
43
44
45
46
47
48
49
50
# File 'lib/git_bundle/commands/push.rb', line 11

def invoke
  return false unless prompt_confirm

  lockfile = Bundler.default_lockfile.basename.to_s
  stale_repos = @repositories.select { |repo| !repo.main && repo.stale? }
  stale_commits_message = stale_repos.map { |repo| "#{repo.name}(#{repo.stale_commits_count})" }.join(', ')

  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 stale_commits_message.empty?
      message = 'Updated Gemfile.lock.'
    else
      message = "Gemfile.lock includes new commits of: #{stale_commits_message}."
    end

    main_repository.commit(message, lockfile)
    puts message
  end

  @repositories.select { |repo| !repo.main && repo.commits_not_pushed_count > 0 }.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)
  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