Class: Snaptoken::Commands::Repo
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
Class Method Details
.name ⇒ Object
2
3
4
|
# File 'lib/snaptoken/commands/repo.rb', line 2
def self.name
"repo"
end
|
.summary ⇒ Object
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
#run ⇒ Object
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
|
# 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|
index = repo.index
index.read_tree(repo.head.target.tree) unless repo.empty?
FileUtils.cd(step_path(step)) do
Dir["**/*"].each do |path|
unless File.directory?(path)
oid = repo.write(File.read(path), :blob)
index.add(path: path, oid: oid, mode: 0100644)
end
end
end
options = {}
options[:tree] = index.write_tree(repo)
options[:message] = step.commit_msg
options[:parents] = repo.empty? ? [] : [repo.head.target]
options[:update_ref] = 'HEAD'
commit_oid = Rugged::Commit.create(repo, options)
if step.name
repo.references.create("refs/tags/#{step.name}", commit_oid)
end
end
repo.checkout_head(strategy: :force)
end
|