Sha256: 407bd3ebcddb31b246d25fa507f5461e566f5d9866a6ed0004ac43fd6a21aa9f

Contents?: true

Size: 946 Bytes

Versions: 9

Compression:

Stored size: 946 Bytes

Contents

require 'thor'
require 'gitx'
require 'gitx/cli/base_command'

module Gitx
  module Cli
    class UpdateCommand < BaseCommand
      desc 'update', 'Update the current branch with latest changes from the remote feature branch and master'
      def update
        say 'Updating '
        say "#{current_branch.name} ", :green
        say 'with latest changes from '
        say config.base_branch, :green

        update_branch(current_branch.name) if remote_branch_exists?(current_branch.name)
        update_branch(config.base_branch)
        run_cmd 'git push origin HEAD'
      end

      private

      def update_branch(branch)
        run_cmd "git pull origin #{branch}"
      rescue
        raise MergeError, 'Merge Conflict Occurred. Please fix merge conflict and rerun the update command'
      end

      def remote_branch_exists?(branch)
        repo.branches.each_name(:remote).include?("origin/#{branch}")
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gitx-2.21.3.ci.135.1 lib/gitx/cli/update_command.rb
gitx-2.21.3 lib/gitx/cli/update_command.rb
gitx-2.21.2.ci.134.1 lib/gitx/cli/update_command.rb
gitx-2.21.2.ci.130.1 lib/gitx/cli/update_command.rb
gitx-2.21.2 lib/gitx/cli/update_command.rb
gitx-2.21.1.ci.125.1 lib/gitx/cli/update_command.rb
gitx-2.21.1 lib/gitx/cli/update_command.rb
gitx-2.21.0.ci.121.1 lib/gitx/cli/update_command.rb
gitx-2.21.0 lib/gitx/cli/update_command.rb