class CommandLine::SubCommands::StartCommand
Public Class Methods
new(new_args, new_input_stream = STDIN)
click to toggle source
Calls superclass method
CommandLine::Command::new
# File lib/git/contest/command_line/sub_commands/start_command.rb, line 15 def initialize(new_args, new_input_stream = STDIN) super end
Public Instance Methods
define_options()
click to toggle source
# File lib/git/contest/command_line/sub_commands/start_command.rb, line 19 def define_options opt_parser.on "-f", "--fetch", "fetch from origin before performing operation." do options[:fetch] = true end end
run()
click to toggle source
# File lib/git/contest/command_line/sub_commands/start_command.rb, line 29 def run p options unless has_next_token? puts "Missing argument <name>" exit 1 end base_branch_name = $MASTER # specify based branch if tokens.length == 2 base_branch_name = tokens[1] end contest_branch_name = "#{tokens[0]}" contest_branch = "#{$PREFIX}/#{contest_branch_name}" Git.require_branch_absent contest_branch # fetch origin/master if options[:fetch] Git.do "fetch -q \"#{$ORIGIN}\"" end # require equal if Git.branch_exists "#{$ORIGIN}/#{$MASTER}" Git.require_branches_equal "#{$MASTER}", "#{$ORIGIN}/#{$MASTER}" end # create branch if ! Git.do "checkout -b \"#{contest_branch}\" \"#{base_branch_name}\"" abort "Could not create contest branch #{contest_branch}" end puts "" puts "Summary of actions:" puts "- A new branch \"#{contest_branch}\" was created, based on \"#{base_branch_name}\"" puts "- You are now on branch \"#{contest_branch}\"" puts "" puts "Now, start committing on your contest. When done, use:" puts "" puts " git contest finish #{contest_branch_name}" puts "" end
set_default_options()
click to toggle source
# File lib/git/contest/command_line/sub_commands/start_command.rb, line 25 def set_default_options options[:fetch] = false if options[:fetch].nil? end