Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Cleaning IS-4644 Enable use of auto-merging resolver #83

Merged
merged 7 commits into from
May 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ another named branch) into your current branch.

sync-branch
sync-branch some-other-branch
#### Automatic Merge Conflict Resolution

Optionally you can add the line `merge_resolver: <path/to/script>` to the `.octopolo.yml` to
have Octopolo try to resolve conflicts automatically via a script upon merge failure.

#### Review Changes In Releases

Expand Down
4 changes: 4 additions & 0 deletions lib/octopolo/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def github_repo
@github_repo || raise(MissingRequiredAttribute, "GitHub Repo is required")
end

def merge_resolver
@merge_resolver
end

def user_notifications
if [NilClass, Array, String].include?(@user_notifications.class)
Array(@user_notifications) if @user_notifications
Expand Down
11 changes: 11 additions & 0 deletions lib/octopolo/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Git
STAGING_PREFIX = "staging"
QAREADY_PREFIX = "qaready"

@resolver_used = nil

include CLIWrapper
extend CLIWrapper # add class-level .cli and .cli= methods

Expand Down Expand Up @@ -132,6 +134,15 @@ def self.merge(branch_name)
Git.if_clean do
Git.fetch
perform "merge --no-ff origin/#{branch_name}", :ignore_non_zero => true
unless Git.clean?
if @resolver_used.nil? && Octopolo.config.merge_resolver
%x(#{Octopolo.config.merge_resolver})
@resolver_used = true
if Git.clean?
merge(branch_name)
end
end
end
raise MergeFailed unless Git.clean?
Git.push
end
Expand Down
10 changes: 10 additions & 0 deletions spec/octopolo/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ module Octopolo
end
end

context "#merge_resolver" do
it "is nil by default" do
Config.new.merge_resolver.should == nil
end

it "returns a string if it has a value" do
Config.new(merge_resolver: "/opt/resolver.sh").merge_resolver.should == "/opt/resolver.sh"
end
end

context "#user_notifications" do
it "is nil by default" do
Config.new.user_notifications.should == nil
Expand Down
4 changes: 2 additions & 2 deletions spec/octopolo/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ module Octopolo
Git.should_receive(:if_clean).and_yield
Git.should_receive(:fetch)
Git.should_receive(:perform).with("merge --no-ff origin/#{branch_name}", :ignore_non_zero => true)
Git.should_receive(:clean?) { true }
Git.should_receive(:clean?).twice { true }
Git.should_receive(:push)

Git.merge branch_name
Expand All @@ -206,7 +206,7 @@ module Octopolo
Git.should_receive(:if_clean).and_yield
Git.should_receive(:fetch)
Git.should_receive(:perform).with("merge --no-ff origin/#{branch_name}", :ignore_non_zero => true)
Git.should_receive(:clean?) { false }
Git.should_receive(:clean?).twice { false }
Git.should_not_receive(:push)

expect { Git.merge branch_name }.to raise_error(Git::MergeFailed)
Expand Down