oleg 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/leg/cli.rb +9 -1
- data/lib/leg/commands.rb +1 -0
- data/lib/leg/commands/base_command.rb +46 -14
- data/lib/leg/commands/diff.rb +6 -11
- data/lib/leg/commands/ref.rb +37 -0
- data/lib/leg/commands/repo.rb +4 -101
- data/lib/leg/commands/undiff.rb +31 -43
- data/lib/leg/commands/unrepo.rb +18 -23
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf4f5f87c6d337bb62e7b3df44db52ec21b28b6d
|
4
|
+
data.tar.gz: 38d29d3088c021488ee771d61093893011964e80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a245d260ca274707448ac4f2c3671f46c4cb8b6a57eab49fa68087b9a65ac876cc3c1ff2a651fc9c814a371ef305e2dadf3cc973ca585366fea5dc81d38fb731
|
7
|
+
data.tar.gz: c120b9ab3436791c35bfe5642e050f7005375cd6c95b36f49cc3c29dffa9334bf5b555947dfcff9f113cea243562c78f83cb296e631397a1300d29ce13e3d4ab
|
data/lib/leg/cli.rb
CHANGED
@@ -5,6 +5,7 @@ class Leg::CLI
|
|
5
5
|
initial_dir = FileUtils.pwd
|
6
6
|
|
7
7
|
last_dir = nil
|
8
|
+
last_dir2 = nil
|
8
9
|
while FileUtils.pwd != last_dir
|
9
10
|
if File.exist?(CONFIG_FILE)
|
10
11
|
@config = YAML.load(File.read(CONFIG_FILE))
|
@@ -13,11 +14,12 @@ class Leg::CLI
|
|
13
14
|
exit!
|
14
15
|
end
|
15
16
|
@config[:path] = FileUtils.pwd
|
16
|
-
@config[:step_path] =
|
17
|
+
@config[:step_path] = last_dir2
|
17
18
|
@config[:orig_path] = initial_dir
|
18
19
|
break
|
19
20
|
end
|
20
21
|
|
22
|
+
last_dir2 = last_dir
|
21
23
|
last_dir = FileUtils.pwd
|
22
24
|
FileUtils.cd('..')
|
23
25
|
end
|
@@ -28,6 +30,12 @@ class Leg::CLI
|
|
28
30
|
def run(args)
|
29
31
|
args = ["help"] if args.empty?
|
30
32
|
cmd_name = args.shift.downcase
|
33
|
+
|
34
|
+
if cmd_name =~ /\A\d+\z/
|
35
|
+
args.unshift(cmd_name)
|
36
|
+
cmd_name = "ref"
|
37
|
+
end
|
38
|
+
|
31
39
|
if cmd = Leg::Commands::LIST.find { |cmd| cmd.name == cmd_name }
|
32
40
|
cmd.new(args, @config).run
|
33
41
|
else
|
data/lib/leg/commands.rb
CHANGED
@@ -13,27 +13,59 @@ class Leg::Commands::BaseCommand
|
|
13
13
|
end
|
14
14
|
|
15
15
|
ERROR_MSG = {
|
16
|
-
config:
|
16
|
+
config: {
|
17
|
+
true: "You are not in a leg working directory.",
|
18
|
+
false: "You are already in a leg working directory."
|
19
|
+
},
|
20
|
+
steps_folder: {
|
21
|
+
true: "There is no steps folder.",
|
22
|
+
false: "There is already a steps folder."
|
23
|
+
},
|
24
|
+
steps: {
|
25
|
+
true: "There are no steps in the steps folder."
|
26
|
+
},
|
27
|
+
repo: {
|
28
|
+
true: "There is no repo folder.",
|
29
|
+
false: "There is already a repo folder."
|
30
|
+
},
|
31
|
+
diff: {
|
32
|
+
true: "There is no steps.diff file."
|
33
|
+
}
|
17
34
|
}
|
18
35
|
|
19
|
-
def needs!(
|
20
|
-
|
36
|
+
def needs!(*whats)
|
37
|
+
options = whats.pop if whats.last.is_a? Hash
|
38
|
+
options ||= {}
|
21
39
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
40
|
+
yes = Array(whats).flatten.map { |w| [w, true] }
|
41
|
+
no = Array(options[:not]).map { |w| [w, false] }
|
42
|
+
|
43
|
+
(yes + no).each do |what, v|
|
44
|
+
valid = false
|
45
|
+
case what
|
46
|
+
when :config
|
47
|
+
valid = true if @config
|
48
|
+
when :steps_folder
|
49
|
+
valid = true if File.exist?(File.join(@config[:path], "steps"))
|
50
|
+
when :steps
|
51
|
+
valid = true if steps.length > 0
|
52
|
+
when :repo
|
53
|
+
valid = true if File.exist?(File.join(@config[:path], "repo"))
|
54
|
+
when :diff
|
55
|
+
valid = true if File.exist?(File.join(@config[:path], "steps.diff"))
|
56
|
+
else
|
57
|
+
raise NotImplementedError
|
58
|
+
end
|
28
59
|
|
29
|
-
|
30
|
-
|
31
|
-
|
60
|
+
if valid != v
|
61
|
+
puts "Error: " + ERROR_MSG[what][v.to_s.to_sym]
|
62
|
+
exit!
|
63
|
+
end
|
32
64
|
end
|
33
65
|
end
|
34
66
|
|
35
67
|
def steps
|
36
|
-
@steps ||= Dir[File.join(@config[:path], "
|
68
|
+
@steps ||= Dir[File.join(@config[:path], "steps/*")].map do |f|
|
37
69
|
name = File.basename(f)
|
38
70
|
name if File.directory?(f) && name =~ /\A\d+(\.\d+)*(-\w+)*\z/
|
39
71
|
end.compact.sort_by { |s| s.split(".").map(&:to_i) }.reject { |s| s.to_i.zero? }
|
@@ -61,7 +93,7 @@ class Leg::Commands::BaseCommand
|
|
61
93
|
end
|
62
94
|
|
63
95
|
def step_path(step)
|
64
|
-
File.join(@config[:path], step)
|
96
|
+
File.join(@config[:path], "steps", step)
|
65
97
|
end
|
66
98
|
|
67
99
|
def select_step(step, &block)
|
data/lib/leg/commands/diff.rb
CHANGED
@@ -8,25 +8,20 @@ class Leg::Commands::Diff < Leg::Commands::BaseCommand
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def run
|
11
|
-
needs! :config
|
12
|
-
|
13
|
-
if !File.exist?(File.join(@config[:path], "repo"))
|
14
|
-
puts "Error: Not in repo mode!"
|
15
|
-
exit!
|
16
|
-
end
|
11
|
+
needs! :config, :repo
|
17
12
|
|
18
13
|
FileUtils.cd(File.join(@config[:path], "repo")) do
|
19
14
|
patches = `git format-patch --stdout -p --no-signature --root master`
|
20
15
|
File.open("../steps.diff", "w") do |f|
|
21
16
|
step_num = 1
|
22
17
|
patches.each_line do |line|
|
23
|
-
if line =~ /^(From|Date)/
|
18
|
+
if line =~ /^(From|Date|index)/
|
24
19
|
# skip
|
25
|
-
elsif line =~ /^Subject: \[[^\]]*\]
|
20
|
+
elsif line =~ /^Subject: \[[^\]]*\](.*)$/
|
26
21
|
f << "\n" unless step_num == 1
|
27
|
-
|
28
|
-
if
|
29
|
-
f << "~~~ step: #{
|
22
|
+
step_name = $1.strip
|
23
|
+
if step_name =~ /^\w+(-\w+)*$/
|
24
|
+
f << "~~~ step: #{step_name}\n"
|
30
25
|
else
|
31
26
|
f << "~~~ step\n"
|
32
27
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Leg::Commands::Ref < Leg::Commands::BaseCommand
|
2
|
+
def self.name
|
3
|
+
"ref"
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.summary
|
7
|
+
"Convert a step number or name to a git commit reference"
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
needs! :config, :repo
|
12
|
+
|
13
|
+
ref = @args.first
|
14
|
+
is_num = (ref =~ /\A\d+\z/)
|
15
|
+
|
16
|
+
FileUtils.cd(@config[:path]) do
|
17
|
+
repo = Rugged::Repository.new("repo")
|
18
|
+
|
19
|
+
walker = Rugged::Walker.new(repo)
|
20
|
+
walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE)
|
21
|
+
walker.push(repo.branches.find { |b| b.name == "master" }.target)
|
22
|
+
walker.each.with_index do |commit, idx|
|
23
|
+
step_num = (idx + 1).to_s
|
24
|
+
step_name = commit.message.lines.first.strip
|
25
|
+
|
26
|
+
if (is_num && ref == step_num) || (!is_num && ref == step_name)
|
27
|
+
puts commit.oid
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
puts "Error: reference not found"
|
33
|
+
exit!
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
data/lib/leg/commands/repo.rb
CHANGED
@@ -4,19 +4,14 @@ class Leg::Commands::Repo < Leg::Commands::BaseCommand
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def self.summary
|
7
|
-
"Convert
|
7
|
+
"Convert steps folder into a version controlled repository"
|
8
8
|
end
|
9
9
|
|
10
10
|
def run
|
11
|
-
needs! :config
|
11
|
+
needs! :config, :steps_folder, :steps, not: :repo
|
12
12
|
|
13
13
|
FileUtils.cd(@config[:path])
|
14
14
|
|
15
|
-
if File.exist?("repo")
|
16
|
-
puts "Error: A repo already exists!"
|
17
|
-
exit!
|
18
|
-
end
|
19
|
-
|
20
15
|
FileUtils.mkdir("repo")
|
21
16
|
repo = Rugged::Repository.init_at("repo")
|
22
17
|
|
@@ -35,106 +30,14 @@ class Leg::Commands::Repo < Leg::Commands::BaseCommand
|
|
35
30
|
|
36
31
|
options = {}
|
37
32
|
options[:tree] = index.write_tree(repo)
|
38
|
-
options[:message] = step
|
33
|
+
options[:message] = step_name(step) || "-"
|
39
34
|
options[:parents] = repo.empty? ? [] : [repo.head.target]
|
40
35
|
options[:update_ref] = 'HEAD'
|
41
36
|
|
42
|
-
|
43
|
-
|
44
|
-
tags = []
|
45
|
-
if idx = step.index('-')
|
46
|
-
tags << step[0...idx]
|
47
|
-
tags << step[(idx+1)..-1]
|
48
|
-
else
|
49
|
-
tags << step
|
50
|
-
end
|
51
|
-
|
52
|
-
tags.each do |tag|
|
53
|
-
repo.references.create("refs/tags/#{tag}", commit_oid)
|
54
|
-
end
|
37
|
+
Rugged::Commit.create(repo, options)
|
55
38
|
end
|
56
39
|
|
57
40
|
repo.checkout_head(strategy: :force)
|
58
|
-
|
59
|
-
File.write("repo/.git/hooks/post-commit", POST_COMMIT_HOOK)
|
60
|
-
File.write("repo/.git/hooks/prepare-commit-msg", PREPARE_COMMIT_MSG_HOOK)
|
61
|
-
File.write("repo/.git/hooks/post-rewrite", POST_REWRITE_HOOK)
|
62
|
-
FileUtils.chmod(0755, "repo/.git/hooks/post-commit")
|
63
|
-
FileUtils.chmod(0755, "repo/.git/hooks/prepare-commit-msg")
|
64
|
-
FileUtils.chmod(0755, "repo/.git/hooks/post-rewrite")
|
65
|
-
|
66
|
-
FileUtils.rm_r(steps)
|
67
41
|
end
|
68
|
-
|
69
|
-
POST_COMMIT_HOOK = <<~'EOF'
|
70
|
-
#!/usr/bin/env ruby
|
71
|
-
|
72
|
-
exit if File.exist?(File.join(ENV['GIT_DIR'], '.git/rebase-merge'))
|
73
|
-
|
74
|
-
require 'rugged'
|
75
|
-
|
76
|
-
repo = Rugged::Repository.discover
|
77
|
-
commit = repo.head.target
|
78
|
-
parts = commit.message.lines.first.strip.split('-').reject(&:empty?)
|
79
|
-
tags = [parts.shift]
|
80
|
-
tags << parts.join('-') unless parts.empty?
|
81
|
-
|
82
|
-
tags.each do |tag|
|
83
|
-
unless repo.tags[tag]
|
84
|
-
repo.references.create("refs/tags/#{tag}", commit.oid)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
EOF
|
88
|
-
|
89
|
-
PREPARE_COMMIT_MSG_HOOK = <<~'EOF'
|
90
|
-
#!/usr/bin/env ruby
|
91
|
-
|
92
|
-
exit if File.exist?(File.join(ENV['GIT_DIR'], '.git/rebase-merge'))
|
93
|
-
|
94
|
-
msg = File.read(ARGV[0])
|
95
|
-
exit if !msg.lines.first.strip.empty?
|
96
|
-
|
97
|
-
require 'rugged'
|
98
|
-
|
99
|
-
repo = Rugged::Repository.discover
|
100
|
-
last_commit = repo.head.target
|
101
|
-
step_num = nil
|
102
|
-
repo.tags.each do |tag|
|
103
|
-
if tag.name =~ /\A\d+(\.\d+)*\z/ && tag.target.oid == last_commit.oid
|
104
|
-
step_num = tag.name
|
105
|
-
break
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
if step_num
|
110
|
-
step_num = step_num.split('.')
|
111
|
-
step_num[-1] = (step_num[-1].to_i + 1).to_s
|
112
|
-
step_num = step_num.join('.')
|
113
|
-
|
114
|
-
msg = File.read(ARGV[0])
|
115
|
-
msg = "#{step_num}-#{msg}"
|
116
|
-
File.write(ARGV[0], msg)
|
117
|
-
end
|
118
|
-
EOF
|
119
|
-
|
120
|
-
POST_REWRITE_HOOK = <<~'EOF'
|
121
|
-
#!/usr/bin/env ruby
|
122
|
-
|
123
|
-
require 'rugged'
|
124
|
-
|
125
|
-
repo = Rugged::Repository.discover
|
126
|
-
|
127
|
-
tags = {}
|
128
|
-
repo.tags.each do |tag|
|
129
|
-
tags[tag.target.oid] = tag.name
|
130
|
-
end
|
131
|
-
|
132
|
-
while line = $stdin.gets
|
133
|
-
old_sha1, new_sha1 = line.split
|
134
|
-
if tags[old_sha1]
|
135
|
-
repo.references.update("refs/tags/#{tags[old_sha1]}", new_sha1)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
EOF
|
139
42
|
end
|
140
43
|
|
data/lib/leg/commands/undiff.rb
CHANGED
@@ -4,57 +4,45 @@ class Leg::Commands::Undiff < Leg::Commands::BaseCommand
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def self.summary
|
7
|
-
"
|
7
|
+
"Convert steps.diff to steps folder"
|
8
8
|
end
|
9
9
|
|
10
10
|
def run
|
11
|
-
needs! :config
|
11
|
+
needs! :config, :diff, not: :steps_folder
|
12
12
|
|
13
13
|
FileUtils.cd(@config[:path]) do
|
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
|
-
cur_diff
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
step_dir = step_num.to_s
|
43
|
-
step_dir += "-#{$1[2..-1]}" if $1
|
44
|
-
if step_num == 1
|
45
|
-
FileUtils.mkdir(step_dir)
|
46
|
-
else
|
47
|
-
FileUtils.cp_r(prev_dir, step_dir)
|
14
|
+
FileUtils.mkdir("steps")
|
15
|
+
FileUtils.cd("steps") do
|
16
|
+
File.open("../steps.diff", "r") do |f|
|
17
|
+
step_num = 0
|
18
|
+
step_dir = nil
|
19
|
+
prev_dir = nil
|
20
|
+
cur_diff = nil
|
21
|
+
while line = f.gets
|
22
|
+
if line =~ /^~~~ step(: \w+(-\w+)*)?$/
|
23
|
+
if cur_diff
|
24
|
+
apply_diff(step_dir, cur_diff)
|
25
|
+
cur_diff = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
step_num += 1
|
29
|
+
step_dir = step_num.to_s
|
30
|
+
step_dir += "-#{$1[2..-1]}" if $1
|
31
|
+
if step_num == 1
|
32
|
+
FileUtils.mkdir(step_dir)
|
33
|
+
else
|
34
|
+
FileUtils.cp_r(prev_dir, step_dir)
|
35
|
+
end
|
36
|
+
prev_dir = step_dir
|
37
|
+
elsif line =~ /^diff --git/
|
38
|
+
apply_diff(step_dir, cur_diff) if cur_diff
|
39
|
+
cur_diff = line
|
40
|
+
elsif cur_diff
|
41
|
+
cur_diff << line
|
48
42
|
end
|
49
|
-
prev_dir = step_dir
|
50
|
-
elsif line =~ /^diff --git/
|
51
|
-
apply_diff(step_dir, cur_diff) if cur_diff
|
52
|
-
cur_diff = line
|
53
|
-
elsif cur_diff
|
54
|
-
cur_diff << line
|
55
43
|
end
|
44
|
+
apply_diff(step_dir, cur_diff) if cur_diff
|
56
45
|
end
|
57
|
-
apply_diff(step_dir, cur_diff) if cur_diff
|
58
46
|
end
|
59
47
|
end
|
60
48
|
end
|
data/lib/leg/commands/unrepo.rb
CHANGED
@@ -4,39 +4,34 @@ class Leg::Commands::Unrepo < Leg::Commands::BaseCommand
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def self.summary
|
7
|
-
"Convert repository into
|
7
|
+
"Convert repository into steps folder"
|
8
8
|
end
|
9
9
|
|
10
10
|
def run
|
11
|
-
needs! :config
|
11
|
+
needs! :config, :repo, not: :steps_folder
|
12
12
|
|
13
|
-
FileUtils.cd(@config[:path])
|
13
|
+
FileUtils.cd(@config[:path]) do
|
14
|
+
FileUtils.mkdir("steps")
|
14
15
|
|
15
|
-
|
16
|
-
puts "Error: repo folder doesn't exist!"
|
17
|
-
exit!
|
18
|
-
end
|
16
|
+
repo = Rugged::Repository.new("repo")
|
19
17
|
|
20
|
-
|
18
|
+
walker = Rugged::Walker.new(repo)
|
19
|
+
walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE)
|
20
|
+
walker.push(repo.branches.find { |b| b.name == "master" }.target)
|
21
|
+
walker.each.with_index do |commit, idx|
|
22
|
+
step_num = (idx + 1).to_s
|
23
|
+
step_name = commit.message.lines.first.strip
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
step_name = step
|
25
|
+
if step_name.empty?
|
26
|
+
step = step_num
|
27
|
+
else
|
28
|
+
step = "#{step_num}-#{step_name}"
|
29
|
+
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
step_name += "-#{parts[1..-1].join('-')}"
|
31
|
+
repo.checkout(commit.oid, strategy: :force,
|
32
|
+
target_directory: step_path(step))
|
32
33
|
end
|
33
|
-
|
34
|
-
step_path = File.join(@config[:path], step_name)
|
35
|
-
|
36
|
-
repo.checkout(commit.oid, strategy: :force, target_directory: step_path)
|
37
34
|
end
|
38
|
-
|
39
|
-
FileUtils.rm_r("repo")
|
40
35
|
end
|
41
36
|
end
|
42
37
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oleg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Ruten
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rugged
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- lib/leg/commands/diff.rb
|
40
40
|
- lib/leg/commands/help.rb
|
41
41
|
- lib/leg/commands/pieces.rb
|
42
|
+
- lib/leg/commands/ref.rb
|
42
43
|
- lib/leg/commands/repo.rb
|
43
44
|
- lib/leg/commands/undiff.rb
|
44
45
|
- lib/leg/commands/unrepo.rb
|