Class: Autoproj::CLI::Reset

Inherits:
InspectionTool show all
Defined in:
lib/autoproj/cli/reset.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

#run(ref_name, options) ⇒ 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
# File 'lib/autoproj/cli/reset.rb', line 9

def run(ref_name, options)
    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 reset if the main configuration is not managed by git"
    end

    # Check if the reflog entry exists
    begin
        importer.rev_parse(pkg, ref_name)
    rescue Autobuild::PackageException
        raise CLIInvalidArguments, "#{ref_name} does not exist, run autoproj log for log entries and autoproj tag without arguments for the tags"
    end

    # Checkout the version file
    versions_file = File.join(
        Workspace::OVERRIDES_DIR,
        Versions::DEFAULT_VERSIONS_FILE_BASENAME
    )
    begin
        file_data = importer.show(pkg, ref_name, versions_file)
        versions_path = File.join(ws.config_dir, versions_file)
        if File.file?(versions_path)
            old_versions_path = "#{versions_path}.old"
            FileUtils.rm_f old_versions_path
            FileUtils.cp versions_path, old_versions_path
        end
        FileUtils.mkdir_p File.join(ws.config_dir, Workspace::OVERRIDES_DIR)
        File.open(versions_path, "w") do |io|
            io.write file_data
        end

        update = CLI::Update.new
        run_args = update.run([], reset: true)
    ensure
        unless options[:freeze]
            FileUtils.rm_f versions_path
            FileUtils.mv old_versions_path, versions_path if old_versions_path
        end
    end
end