Class: FlashFlow::Merge::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/flash_flow/merge/base.rb

Direct Known Subclasses

Acceptance, Master

Defined Under Namespace

Classes: OutOfSyncWithRemote, UnmergeableBranch, VersionError

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Base

Returns a new instance of Base.



19
20
21
22
23
24
# File 'lib/flash_flow/merge/base.rb', line 19

def initialize(opts={})
  @local_git = Git.new(Config.configuration.git, logger)
  @git = ShadowGit.new(Config.configuration.git, logger)
  @lock = Lock::Base.new(Config.configuration.lock)
  @notifier = Notifier::Base.new(Config.configuration.notifier)
end

Instance Method Details

#check_repoObject



30
31
32
33
34
# File 'lib/flash_flow/merge/base.rb', line 30

def check_repo
  if @local_git.staged_and_working_dir_files.any?
    raise RuntimeError.new('You have changes in your working directory. Please stash and try again')
  end
end

#check_versionObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/flash_flow/merge/base.rb', line 36

def check_version
  data_version = @data.version
  return if data_version.nil?

  written_version = data_version.split(".").map(&:to_i)
  running_version = FlashFlow::VERSION.split(".").map(&:to_i)

  unless written_version[0] < running_version[0] ||
      (written_version[0] == running_version[0] && written_version[1] <= running_version[1]) # Ignore the point release number
    raise RuntimeError.new("Your version of flash flow (#{FlashFlow::VERSION}) is behind the version that was last used (#{data_version}) by a member of your team. Please upgrade to at least #{written_version[0]}.#{written_version[1]}.0 and try again.")
  end
end

#git_merge(branch) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/flash_flow/merge/base.rb', line 66

def git_merge(branch)
  merger = BranchMerger.new(@git, branch)
  forget_rerere = is_working_branch(branch) && @rerere_forget

  merger.do_merge(forget_rerere)

  merger
end

#is_working_branch(branch) ⇒ Object



75
76
77
# File 'lib/flash_flow/merge/base.rb', line 75

def is_working_branch(branch)
  branch.ref == @git.working_branch
end

#loggerObject



26
27
28
# File 'lib/flash_flow/merge/base.rb', line 26

def logger
  @logger ||= FlashFlow::Config.configuration.logger
end

#merge_branches(branches) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/flash_flow/merge/base.rb', line 49

def merge_branches(branches)
  ordered_branches = MergeOrder.new(@git, branches).get_order
  ordered_branches.each_with_index do |branch, index|
    branch.merge_order = index + 1

    remote = @git.fetch_remote_for_url(branch.remote_url)
    if remote.nil?
      raise RuntimeError.new("No remote found for #{branch.remote_url}. Please run 'git remote add *your_remote_name* #{branch.remote_url}' and try again.")
    end

    @git.fetch(branch.remote)
    merger = git_merge(branch)

    yield(branch, merger)
  end
end