Class: Commands::Tag
- Inherits:
-
Object
- Object
- Commands::Tag
- Defined in:
- lib/commands/tag.rb
Instance Method Summary collapse
-
#options ⇒ Object
holds the options that were passed you can set any initial defaults here.
- #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/tag.rb', line 13 def @options ||= { } end |
#register(opts, global_options) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/commands/tag.rb', line 25 def register(opts, ) opts. = "Usage: tag [options]" opts.description = "Apply or delete a tag for all taggable repos in a config" opts.on('-t', "--tag name", "Required - Name of the tag.") do |v| [:tag] = v end opts.on('-d', "--delete", "When set causes tag to be deleted.") do |v| [:delete] = true end opts.on("--commit-and-push", "Commit any local changes and then push the remote - should only be used by the build system.") do |v| [:commit_and_push] = true end end |
#required_options ⇒ Object
required options
19 20 21 22 23 |
# File 'lib/commands/tag.rb', line 19 def @required_options ||= Set.new [ :tag, ] end |
#run(global_options) ⇒ Object
43 44 45 46 47 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 |
# File 'lib/commands/tag.rb', line 43 def run() # see if we can open the config file - we append the .config suffix # the file is expected to be in JSON format tag = [:tag] delete_tag = !![:delete] commit_and_push = !![:commit_and_push] # the !! forces conversion to a boolean if (commit_and_push && delete_tag) raise "You cannot use --commit-and-push with --delete." end info = EbmSharedLib.get_config_from_top_dir # other than prepare, any commands that work across the repos expect you to start # in the containing directory (i.e. if your config is named iphone_3.1, you are expected # to be in that directory when you run the command). top_dir = "#{Dir.pwd}" repos = info[:repos] repos.each do |repo| if repo[:taggable] repo_name = EbmSharedLib.get_repo_name(repo[:git_path]) repo_path = "#{top_dir}/#{repo_name}" if delete_tag cmd = "git tag -d #{tag}" if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0 raise "Deleting tag failed for #{repo_name}." end cmd = "git push origin :refs/tags/#{tag}" if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0 raise "Deleting tag failed failed for #{repo_name}." end else if commit_and_push # they want to commit whatever has changed and push to current remote # first grab the current branch name branch = EbmSharedLib.get_current_branch(repo, repo_path) # we have the local branch so now commit and push to the remote branch cmd = "git commit -am \"Committing changes via ebm tag --commit_and_push for tag #{tag}.\"" EbmSharedLib::CL.do_cmd_result(cmd, repo_path) # ignore any error # now push what we just committed cmd = "git push origin #{branch}" if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0 raise "Push failed failed for #{repo_name}." end end cmd = "git tag #{tag}" if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0 raise "Tagging operation failed for #{repo_name}. Make sure you are in the top level #{config_name} directory." end cmd = "git push origin refs/tags/#{tag}" if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0 raise "Tagging operation failed for #{repo_name}. Make sure you are in the top level #{config_name} directory." end end end end end |