def unmerged_commits?(branch_name, verbose=true)
locations = []
locations << '' if branch_exists?(:local, branch_name)
locations << 'origin/' if branch_exists?(:remote, branch_name)
locations = locations.repeated_permutation(2).to_a
if locations.empty?
puts 'Nothing to do. All cleaned up already.' if verbose
return false
end
responses = locations.collect { |loc|
git_call "cherry #{loc.first}#{target_branch} #{loc.last}#{branch_name}"
}
unmerged_commits = responses.reject { |response|
response.empty? or response.include?('fatal: Unknown commit') or
response.split("\n").reject { |x| x.index('-') == 0 }.empty?
}
if unmerged_commits.empty?
false
else
puts "Unmerged commits on branch '#{branch_name}'."
true
end
end