Sha256: 54fb4fbb4eda932cac86a3acf8bfa485dc840fe5ddd5b2d94a0cb98d728bbc11

Contents?: true

Size: 1.17 KB

Versions: 21

Compression:

Stored size: 1.17 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 )
        VALID_BRANCH_NAME_REGEX = /^[A-Za-z0-9\-_]+$/

        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

          checkout_branch Thegarage::Gitx::BASE_BRANCH
          run_cmd 'git pull'
          repo.create_branch branch_name, Thegarage::Gitx::BASE_BRANCH
          checkout_branch branch_name
        end

        private

        def valid_new_branch_name?(branch)
          return false if repo_branches.include?(branch)
          branch =~ VALID_BRANCH_NAME_REGEX
        end

        def repo_branches
          @branch_names ||= repo.branches.each_name.map do |branch|
            branch.split('/').last
          end
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
thegarage-gitx-2.14.0 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.13.1 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.13.0 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.12.0 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.11.0 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.10.2 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.10.1 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.10.0 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.9.0 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.8.1 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.8.0 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.7.2 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.7.1 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.7.0 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.6.0 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.5.1 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.5.0 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.5.0.beta5 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.5.0.beta4 lib/thegarage/gitx/cli/start_command.rb
thegarage-gitx-2.5.0.beta3 lib/thegarage/gitx/cli/start_command.rb