Sha256: dc8a9919098a62f8ab71596da300ff46069af90d6853b8f46d537f795fd02c8a

Contents?: true

Size: 1.05 KB

Versions: 28

Compression:

Stored size: 1.05 KB

Contents

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

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 Gitx::BASE_BRANCH
        run_cmd 'git pull'
        repo.create_branch branch_name, 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

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
gitx-2.17.0.pre.ci.101.1 lib/gitx/cli/start_command.rb
gitx-2.17.0.pre lib/gitx/cli/start_command.rb
gitx-2.17.0.pre.ci.98.1 lib/gitx/cli/start_command.rb
gitx-2.16.0.ci.91.1 lib/gitx/cli/start_command.rb
gitx-2.16.0 lib/gitx/cli/start_command.rb
gitx-2.16.0.ci.89.1 lib/gitx/cli/start_command.rb
gitx-2.16.0.pre.ci.88.1 lib/gitx/cli/start_command.rb
gitx-2.16.0.pre.ci.85.1 lib/gitx/cli/start_command.rb
gitx-2.16.0.pre lib/gitx/cli/start_command.rb
gitx-2.16.0.pre.ci.81.1 lib/gitx/cli/start_command.rb
gitx-2.15.0 lib/gitx/cli/start_command.rb
gitx-2.15.0.ci.75.1 lib/gitx/cli/start_command.rb
gitx-2.14.2.ci.70.1 lib/gitx/cli/start_command.rb
gitx-2.14.1.ci.62.1 lib/gitx/cli/start_command.rb
gitx-2.14.1 lib/gitx/cli/start_command.rb
gitx-2.14.0.ci.56.1 lib/gitx/cli/start_command.rb
gitx-2.14.0 lib/gitx/cli/start_command.rb
gitx-2.13.7 lib/gitx/cli/start_command.rb
gitx-2.13.7.ci.52.1 lib/gitx/cli/start_command.rb
gitx-2.13.6 lib/gitx/cli/start_command.rb