class Gitx::Cli::StartCommand

Constants

EXAMPLE_BRANCH_NAMES
VALID_BRANCH_NAME_REGEX

Public Instance Methods

start(branch_name = nil) click to toggle source
# File lib/gitx/cli/start_command.rb, line 13
def start(branch_name = nil)
  branch_name = ask("What would you like to name your branch? (ex: #{EXAMPLE_BRANCH_NAMES.sample})") until valid_new_branch_name?(branch_name)

  checkout_branch config.base_branch
  run_git_cmd 'pull'
  repo.create_branch branch_name, config.base_branch
  checkout_branch branch_name
  run_git_cmd('commit', '--allow-empty', '--message', commit_message(branch_name))
end

Private Instance Methods

commit_message(branch_name) click to toggle source
# File lib/gitx/cli/start_command.rb, line 25
def commit_message(branch_name)
  message = "[gitx] Start work on #{branch_name}"
  if (issue = options[:issue])
    issue = issue.dup.prepend('#') if issue =~ /\A\d+\z/
    message += "\n\nConnected to #{issue}"
  end
  message
end
repo_branches() click to toggle source

get list of local and remote branches

# File lib/gitx/cli/start_command.rb, line 41
def repo_branches
  @repo_branches ||= repo.branches.each_name.map do |branch|
    branch.gsub('origin/', '')
  end
end
valid_new_branch_name?(branch) click to toggle source
# File lib/gitx/cli/start_command.rb, line 34
def valid_new_branch_name?(branch)
  return false if repo_branches.include?(branch)

  Rugged::Reference.valid_name?("refs/heads/#{branch}")
end