Sha256: bd00a5cbc7f0ee208312aef7099191945dbc3c6c3f2da99025fd8d829f6b5399

Contents?: true

Size: 975 Bytes

Versions: 2

Compression:

Stored size: 975 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 Gitx::BASE_BRANCH, :green

        update_branch(current_branch.name) if remote_branch_exists?(current_branch.name)
        update_branch(Gitx::BASE_BRANCH)
        run_cmd 'git push origin HEAD'
      end

      private

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gitx-2.13.2 lib/gitx/cli/update_command.rb
gitx-2.13.1 lib/gitx/cli/update_command.rb