Sha256: 3b1ea174d1d3f9e4be1723f26251c808e3db5d123918c24667ace4770d1a44a1

Contents?: true

Size: 1.69 KB

Versions: 3

Compression:

Stored size: 1.69 KB

Contents

#!/usr/bin/env ruby

#
# git-contest-init
# https://github.com/sh19910711/git-contest
#
# Copyright (c) 2013 Hiroyuki Sano <sh19910711 at gmail.com>
# Licensed under the MIT-License.
#

$:.unshift File.expand_path('../../lib', __FILE__)
require 'git/contest/common'
require 'trollop'
require 'highline/import'

init

sub_commands = %w()
options = Trollop::options do
  version "git-contest #{Git::Contest::VERSION} (c) 2013 Hiroyuki Sano"
  opt(
    :defaults,
    "Use default branch naming conventions.",
    :type => :flag,
    :default => false,
    :required => false,
  )
  opt(
    :force,
    "force setting of git-contest branches, even if already configured.",
    :short => :f,
    :type => :flag,
    :default => false,
    :required => false,
  )
  stop_on sub_commands
end

if git_contest_is_initialized && ! options[:force]
  puts "Already initialized for git-contest."
  puts "To force reinitialization, use: git contest init -f"
  exit 0
end

# run commands
if ! git_do_no_echo 'rev-parse --git-dir'
  git_do 'init'
end

# init main
if git_contest_has_master_configured
  master_branch = git_do 'config --get git.contest.branch.master'
elsif options[:defaults]
  master_branch = 'master'
else
  master_branch = ask('Master branch name: ') do |q|
    q.default = 'master'
  end
end

if options[:defaults]
  prefix = 'contest'
else
  prefix = ask('Prefix of contest branch name:  ') do |q|
    q.default = 'contest'
  end
end

if git_repo_is_headless
  git_do 'symbolic-ref', 'HEAD', "\"refs/heads/#{master_branch}\""
  git_do 'commit --allow-empty --quiet -m "Initial commit"'
end

# save config
git_do 'config', 'git.contest.branch.master', master_branch
git_do 'config', 'git.contest.branch.prefix', prefix

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
git-contest-0.0.3 bin/git-contest-init
git-contest-0.0.2 bin/git-contest-init
git-contest-0.0.1 bin/git-contest-init