Class: Commands::Prepare
- Inherits:
-
Object
- Object
- Commands::Prepare
- Defined in:
- lib/commands/prepare.rb
Instance Method Summary collapse
-
#options ⇒ Object
holds the options that were passed you can set any initial defaults here.
-
#prepare_repo(repo, top_dir, initials, nobranch) ⇒ Object
prepare a single repo and create a local and tracking branch if it should have one if the repo specifies a branch then we will do the initial fetch from that branch if the create_dev_branch flag is set, we will create a local and tracking branch with the developer initials prepended.
- #register(opts, global_options) ⇒ Object
-
#required_options ⇒ Object
required options.
- #run(global_options) ⇒ Object
Instance Method Details
#options ⇒ Object
holds the options that were passed you can set any initial defaults here
13 14 15 16 |
# File 'lib/commands/prepare.rb', line 13 def ||= { } end |
#prepare_repo(repo, top_dir, initials, nobranch) ⇒ Object
prepare a single repo and create a local and tracking branch if it should have one if the repo specifies a branch then we will do the initial fetch from that branch if the create_dev_branch flag is set, we will create a local and tracking branch with the developer initials prepended
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/commands/prepare.rb', line 48 def prepare_repo(repo, top_dir, initials, nobranch) git_path = repo[:git_path] branch = repo[:branch] create_dev_branch = (repo[:create_dev_branch] == true) && (!nobranch) tag = repo[:tag] parent_path = repo[:parent_path] if tag && branch raise "We only support branching relative to HEAD, you cannot specify a branch:#{branch} and a tag:#{tag}." end if tag && create_dev_branch raise "We do not support creating dev branches when using a tag" end # build the parent path if we have one and make it the new top dir if parent_path Dir.chdir(top_dir){ FileUtils.mkpath(parent_path) } top_dir = "#{top_dir}/#{parent_path}" end # first clone the repo cmd = "git clone #{git_path}" if EbmSharedLib::CL.do_cmd_result(cmd, top_dir) != 0 raise "Cloning repo at #{git_path} failed." end # extract the directory name that this repo ended up in repo_name = EbmSharedLib.get_repo_name(git_path) repo_path = "#{top_dir}/#{repo_name}" # now set up the remote tracking base branch if we have one if branch cmd = "git checkout --track origin/#{branch}" if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0 raise "Checking out branch #{branch} for #{repo_name} failed." end # now create the developer branch off of the base branch if create_dev_branch dev_branch_name = "#{initials}_#{branch}" cmd = "git checkout -B #{dev_branch_name} && git push -u origin #{dev_branch_name}" if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0 raise "Unable to create local and tracking developer branch #{dev_branch_name} for #{repo_name}." end end elsif tag # they are using a tag so don't create dev branches cmd = "git checkout #{tag}" if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0 raise "Unable to checkout tag:#{tag} for #{repo_name}." end end # pull any submodules cmd = "git submodule init && git submodule update" if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0 raise "Cloning submodules in repo at #{git_path} failed." end end |
#register(opts, global_options) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/commands/prepare.rb', line 26 def register(opts, ) opts. = "Usage: prepare [options]" opts.description = "Prepare your build environment" opts.on('-c', "--config name", "Required - Name of the config we are preparing from.") do |v| [:config] = v end opts.on('-i', "--initials name", "Required - Initials prepended to your branch For example --initials gws will result in something like gws_iphone_3.0.") do |v| [:initials] = v end opts.on("--nobranch", "Don't create developer branch.") do |v| [:nobranch] = v end end |
#required_options ⇒ Object
required options
19 20 21 22 23 24 |
# File 'lib/commands/prepare.rb', line 19 def ||= Set.new [ :config, :initials, ] end |
#run(global_options) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/commands/prepare.rb', line 112 def run() # see if we can open the config file - we append the .config suffix # the file is expected to be in JSON format config_name = [:config] initials = [:initials] nobranch = [:nobranch] # try to make sure the repo is available EbmSharedLib.prepare_config_repo info = EbmSharedLib.read_repo_config(config_name) # Now that we have the json, prepare the world by creating a directory with the config name and placing # the various repos beneath that. The directory is created relative to the current directory. top_dir = "#{Dir.pwd}/#{config_name}" raise "Cannot prepare since top level directory already exists: #{top_dir}" if File.directory?(top_dir) Dir::mkdir(top_dir) repos = info[:repos] repos.each do |repo| prepare_repo(repo, top_dir, initials, nobranch) end end |