Class: Leg::Commands::Unrepo
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_name, #step_path, #steps
Class Method Details
.name ⇒ Object
2
3
4
|
# File 'lib/leg/commands/unrepo.rb', line 2
def self.name
"unrepo"
end
|
.summary ⇒ Object
6
7
8
|
# File 'lib/leg/commands/unrepo.rb', line 6
def self.summary
"Convert repository into steps folder"
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
|
# File 'lib/leg/commands/unrepo.rb', line 10
def run
needs! :config, :repo, not: :steps_folder
FileUtils.cd(@config[:path]) do
FileUtils.mkdir("steps")
repo = Rugged::Repository.new("repo")
walker = Rugged::Walker.new(repo)
walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE)
walker.push(repo.branches.find { |b| b.name == "master" }.target)
walker.each.with_index do |commit, idx|
step_num = (idx + 1).to_s
step_name = commit.message.lines.first.strip
if step_name.empty?
step = step_num
else
step = "#{step_num}-#{step_name}"
end
repo.checkout(commit.oid, strategy: :force,
target_directory: step_path(step))
end
end
end
|