Skip to content

Commit

Permalink
Merge pull request #83 from sportngin/IS-4644-springclean-automerge
Browse files Browse the repository at this point in the history
Spring Cleaning IS-4644 Enable use of auto-merging resolver
  • Loading branch information
Andy Fleener committed May 17, 2016
2 parents c2d81b0 + 128ff1b commit d7a4285
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
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

0 comments on commit d7a4285

Please sign in to comment.