Sha256: 2dbe02b3fff8a5ef61cfc0fc933157292764daa2e706c36d357e1b7fe1ea5b0d

Contents?: true

Size: 1 KB

Versions: 6

Compression:

Stored size: 1 KB

Contents

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

module Thegarage
  module Gitx
    module Cli
      class StartCommand < BaseCommand
        EXAMPLE_BRANCH_NAMES = %w( api-fix-invalid-auth desktop-cleanup-avatar-markup share-form-add-edit-link )

        desc 'start', 'start a new git branch with latest changes from master'
        def start(branch_name = nil)
          until valid_new_branch_name?(branch_name)
            branch_name = ask("What would you like to name your branch? (ex: #{EXAMPLE_BRANCH_NAMES.sample})")
          end

          run_cmd "git checkout #{Thegarage::Gitx::BASE_BRANCH}"
          run_cmd 'git pull'
          run_cmd "git checkout -b #{branch_name}"
        end

        private

        def valid_new_branch_name?(branch)
          remote_branches = Rugged::Branch.each_name(repo, :remote).to_a.map { |branch| branch.split('/').last }
          branch =~ /^[A-Za-z0-9\-_]+$/ && !remote_branches.include?(branch)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
thegarage-gitx-2.0.3 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.0.2 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.0.1 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.0.0 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.0.0.pre2 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.0.0.pre1 lib/thegarage/gitx/cli/start_command.rb