Class: Snaptoken::Commands::Repo

Inherits:
BaseCommand show all
Defined in:
lib/snaptoken/commands/repo.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::ERROR_MSG

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCommand

#current_or_latest_step, #current_step, inherited, #initialize, #latest_step, #needs!, #select_step, #step_path, #steps

Constructor Details

This class inherits a constructor from Snaptoken::Commands::BaseCommand

Class Method Details

.nameObject



2
3
4
# File 'lib/snaptoken/commands/repo.rb', line 2

def self.name
  "repo"
end

.summaryObject



6
7
8
# File 'lib/snaptoken/commands/repo.rb', line 6

def self.summary
  "Convert steps folder into a version controlled repository"
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/snaptoken/commands/repo.rb', line 10

def run
  needs! :config, :steps_folder, :steps, not: :repo

  FileUtils.cd(@config[:path])

  FileUtils.mkdir("repo")
  repo = Rugged::Repository.init_at("repo")

  steps.each do |step|
    commit_oid = add_commit(repo, step, step_path(step))

    if step.name
      repo.references.create("refs/tags/#{step.name}", commit_oid)
    end
  end

  if Dir.exist? "repo-extra"
    add_commit(repo, nil, [step_path(latest_step), "repo-extra"])
  end

  repo.checkout_head(strategy: :force)
end