Sha256: 127ff9149f32297706854a46920d6f81af1592211dc9e897878e686b294d7ec2

Contents?: true

Size: 1.48 KB

Versions: 5

Compression:

Stored size: 1.48 KB

Contents

require 'thor'
require 'thegarage/gitx'
require 'thegarage/gitx/cli/base_command'
require 'thegarage/gitx/cli/update_command'

module Thegarage
  module Gitx
    module Cli
      class IntegrateCommand < BaseCommand
        desc 'integrate', 'integrate the current branch into one of the aggregate development branches (default = staging)'
        def integrate(target_branch = 'staging')
          branch = current_branch.name
          assert_integratable_branch!(branch, target_branch)

          UpdateCommand.new.update

          say "Integrating "
          say "#{branch} ", :green
          say "into "
          say target_branch, :green

          refresh_branch_from_remote target_branch
          run_cmd "git merge #{branch}"
          run_cmd "git push origin HEAD"
          checkout_branch branch
        end

        private

        def assert_integratable_branch!(branch, target_branch)
          assert_not_protected_branch!(branch, 'integrate') unless aggregate_branch?(target_branch)
          raise "Only aggregate branches are allowed for integration: #{AGGREGATE_BRANCHES}" unless aggregate_branch?(target_branch) || target_branch == Thegarage::Gitx::BASE_BRANCH
        end

        # nuke local branch and pull fresh version from remote repo
        def refresh_branch_from_remote(target_branch)
          run_cmd "git branch -D #{target_branch}", :allow_failure => true
          run_cmd "git fetch origin"
          checkout_branch target_branch
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
thegarage-gitx-2.4.1 lib/thegarage/gitx/cli/integrate_command.rb
thegarage-gitx-2.4.0 lib/thegarage/gitx/cli/integrate_command.rb
thegarage-gitx-2.4.0.pre1 lib/thegarage/gitx/cli/integrate_command.rb
thegarage-gitx-2.3.0 lib/thegarage/gitx/cli/integrate_command.rb
thegarage-gitx-2.3.0.pre1 lib/thegarage/gitx/cli/integrate_command.rb