lib/straight_line/common/feature/land.rb in straight_line-0.1.1.0 vs lib/straight_line/common/feature/land.rb in straight_line-0.1.2.0

- old
+ new

@@ -20,31 +20,36 @@ 'Commit your changes before creating a diff' end def land(_args = {}) feature_name = current_feature - pull_cmd = GitCommands::Pull.new('master') - pull_cmd.run - GitCommands::Merge.new(feature_name, 'master').run - - begin - GitCommands::Commit.new("Merge master into #{feature_name}", '').run - rescue StandardError => e - unless e.message.match %r[nothing to commit] - raise e - end - end + merge_master_to_feature(feature_name) GitCommands::Push.new(feature_name).run + merge_feature_to_master(feature_name) + GitCommands::Push.new(feature_name, delete: true).run + Command.new('git checkout master').run + Util.logger.info 'Changes landed to master, on master branch now.' + end + + def merge_feature_to_master(feature_name) if pull_request_closed?(feature_name) - Util.logger.info %{#{feature_name} was merged in github. - You're repo is up-to-date with remote} + Util.logger.info %(#{feature_name} was merged in github. + You're repo is up-to-date with remote) else GitCommands::Merge.new('master', feature_name).run GitCommands::Push.new('master').run end - GitCommands::Push.new(feature_name, delete: true).run - Command.new('git checkout master').run - Util.logger.info 'Changes landed to master, on master branch now.' + end + + def merge_master_to_feature(feature_name) + GitCommands::Pull.new('master').run + GitCommands::Merge.new(feature_name, 'master').run + + begin + GitCommands::Commit.new("Merge master into #{feature_name}", '').run + rescue StandardError => e + raise e unless e.message =~ /nothing to commit/ + end end def pull_request_closed?(feature_name) p = Github.pull_request_for_feature feature_name p.nil? || p.state == 'closed'