Class: Autoproj::CLI::Tag

Inherits:
Base
  • Object
show all
Defined in:
lib/autoproj/cli/tag.rb

Instance Attribute Summary

Attributes inherited from Base

#ws

Instance Method Summary collapse

Methods inherited from Base

#export_env_sh, #initialize, #normalize_command_line_package_selection, #notify_env_sh_updated, #resolve_selection, #resolve_user_selection, validate_options, #validate_options, #validate_user_selection

Methods included from Ops::Tools

#common_options, #create_autobuild_package, #load_autoprojrc, #load_main_initrb

Constructor Details

This class inherits a constructor from Autoproj::CLI::Base

Instance Method Details

#run(arguments, options = Hash.new) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/autoproj/cli/tag.rb', line 9

def run(arguments, options = Hash.new)
    tag_name, *user_selection = *arguments
    ws.load_config
    main_package_set = LocalPackageSet.new(ws)

    pkg = main_package_set.create_autobuild_package
    importer = pkg.importer
    if !importer || !importer.kind_of?(Autobuild::Git)
        raise CLIInvalidArguments, "cannot use autoproj tag if the main configuration is not managed by git"
    end

    versions_file = File.join(
        Workspace::OVERRIDES_DIR,
        Versions::DEFAULT_VERSIONS_FILE_BASENAME
    )

    if tag_name.nil?
        importer = pkg.importer
        all_tags = importer.run_git_bare(pkg, "tag")
        all_tags.sort.each do |tag|
            next if tag =~ /\^/

            begin importer.show(pkg, "refs/tags/#{tag}", versions_file)
                  puts tag
            rescue Autobuild::PackageException
            end
        end
        return
    end

    # Check if the tag already exists
    begin
        importer.rev_parse(pkg, "refs/tags/#{tag_name}")
        raise CLIInvalidArguments, "tag #{tag_name} already exists"
    rescue Autobuild::PackageException
    end

    message = options[:message] ||
              "autoproj created tag #{tag_name}"
    commit_id = Ops::Snapshot.create_commit(pkg, versions_file, message) do |io|
        versions = CLI::Versions.new(ws)
        Autoproj.message "creating versions file, this may take a while"
        versions.run(user_selection,
                     package_sets: options[:package_sets],
                     save: io.path,
                     replace: true,
                     keep_going: options[:keep_going])
    end

    importer.run_git_bare(pkg, "tag", tag_name, commit_id)
end