Class: GitBundle::Push

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

Constant Summary

Constants included from Console

Console::COLORS

Instance Method Summary collapse

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

#invokeObject



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

  message = @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
    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: #{commit_message}", 'Gemfile.lock')
  end

  main_repository.push(@args)
end

#prompt_confirmObject



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