Class: Autoproj::CLI::Commit

Inherits:
InspectionTool show all
Defined in:
lib/autoproj/cli/commit.rb

Instance Attribute Summary

Attributes inherited from Base

#ws

Instance Method Summary collapse

Methods inherited from InspectionTool

#finalize_setup, #initialize_and_load

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

#default_message(tag_name) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/autoproj/cli/commit.rb', line 8

def default_message(tag_name)
    if tag_name
        "autoproj created tag #{tag_name}"
    else
        "autoproj created version commit"
    end
end

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



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
# File 'lib/autoproj/cli/commit.rb', line 16

def run(user_selection, options = Hash.new)
    tag_name = options[:tag]
    ws.load_config
    pkg = ws.manifest.main_package_set.create_autobuild_package
    importer = pkg.importer
    if !importer || !importer.kind_of?(Autobuild::Git)
        raise CLIInvalidArguments, "cannot use autoproj commit if the main configuration is not managed by git"
    end

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

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

    versions = CLI::Versions.new(ws)
    Autoproj.message "creating versions file, this may take a while"
    versions.run(user_selection,
                 save: versions_file,
                 package_sets: options[:package_sets],
                 replace: true,
                 keep_going: options[:keep_going],
                 deps: options[:deps])

    importer.run_git(pkg, "add", versions_file)
    message = options[:message] || default_message(tag_name)

    importer.run_git(pkg, "commit", "-m", message)
    importer.run_git(pkg, "tag", tag_name) unless tag_name.nil?
end