oleg 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1959ad4dcb10af988cca489723033a91a9ff9dd5
4
- data.tar.gz: a376caa659e4830dfc91ad8137ef62f752a6ecd4
3
+ metadata.gz: 7e4f90f727a10550fe24d3d8a9f97c8c05dd38b5
4
+ data.tar.gz: 98368a97bdfb2e8bc5709ae44e14bb41b72f6f40
5
5
  SHA512:
6
- metadata.gz: 4b20e1e39fe317138b9b6d61156026c59b6836984f7046239b71a422745463a820207b5436fbc15feb175de31801e21b27b07b158b4f56ba956adf8c75e4a8ad
7
- data.tar.gz: 4dbeceee4d089a6e7e16bd2d0cd0281b2f1e8a34760a81d62c79f26d4d50630446e5fda29efb03a1114aa03bb40d3294b580ae561851da918251327dbfa3f04e
6
+ metadata.gz: 1aa44cfd06b459245ae6c0e76ab8da5e80c9d9d8927f6dc378e61f50dad04b18c9837c6d1ad44b911589f3c5c8e94b847e17edaf8062616a88466b16676cea45
7
+ data.tar.gz: f45af9fcada0e077125787f8c78fb84dbe405cd801950819b41479dae1da874bb7d26ea7c37dab5ac815424f7002884433092489cde45514c575c7d5eaa1830f
@@ -36,7 +36,7 @@ class Leg::Commands::BaseCommand
36
36
  @steps ||= Dir[File.join(@config[:path], "*")].map do |f|
37
37
  name = File.basename(f)
38
38
  name if File.directory?(f) && name =~ /\A\d+(\.\d+)*(-\w+)*\z/
39
- end.compact.sort_by { |s| s.split(".").map(&:to_i) }
39
+ end.compact.sort_by { |s| s.split(".").map(&:to_i) }.reject { |s| s.to_i.zero? }
40
40
  end
41
41
 
42
42
  def current_step
@@ -53,6 +53,13 @@ class Leg::Commands::BaseCommand
53
53
  current_step || latest_step
54
54
  end
55
55
 
56
+ def step_name(step)
57
+ parts = step.split('-')
58
+ if parts.length > 1
59
+ parts[1..-1].join('-')
60
+ end
61
+ end
62
+
56
63
  def step_path(step)
57
64
  File.join(@config[:path], step)
58
65
  end
@@ -0,0 +1,42 @@
1
+ class Leg::Commands::Diff < Leg::Commands::BaseCommand
2
+ def self.name
3
+ "diff"
4
+ end
5
+
6
+ def self.summary
7
+ "Convert repo into a single file containing diffs for each step"
8
+ end
9
+
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
17
+
18
+ FileUtils.cd(File.join(@config[:path], "repo")) do
19
+ patches = `git format-patch --stdout -p --no-signature --root master`
20
+ File.open("../steps.diff", "w") do |f|
21
+ step_num = 1
22
+ patches.each_line do |line|
23
+ if line =~ /^(From|Date)/
24
+ # skip
25
+ elsif line =~ /^Subject: \[[^\]]*\] (.*)$/
26
+ f << "\n" unless step_num == 1
27
+ parts = $1.split('-')
28
+ if parts.length >= 2
29
+ f << "~~~ step: #{parts[1..-1].join('-')}\n"
30
+ else
31
+ f << "~~~ step\n"
32
+ end
33
+ step_num += 1
34
+ elsif line.chomp.length > 0
35
+ f << line
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
@@ -0,0 +1,70 @@
1
+ class Leg::Commands::Undiff < Leg::Commands::BaseCommand
2
+ def self.name
3
+ "undiff"
4
+ end
5
+
6
+ def self.summary
7
+ "Conver steps.diff to step folders"
8
+ end
9
+
10
+ def run
11
+ needs! :config
12
+
13
+ FileUtils.cd(@config[:path]) do
14
+ if !File.exist?("steps.diff")
15
+ puts "Error: steps.diff doesn't exist!"
16
+ exit!
17
+ end
18
+
19
+ if !steps.empty?
20
+ puts "Error: Step folders already exist!"
21
+ exit!
22
+ end
23
+
24
+ if File.exist?("repo")
25
+ puts "Error: In repo mode!"
26
+ exit!
27
+ end
28
+
29
+ File.open("steps.diff", "r") do |f|
30
+ step_num = 0
31
+ step_dir = nil
32
+ prev_dir = nil
33
+ cur_diff = nil
34
+ while line = f.gets
35
+ if line =~ /^~~~ step(: \w+(-\w+)*)?$/
36
+ if cur_diff
37
+ apply_diff(step_dir, cur_diff)
38
+ cur_diff = nil
39
+ end
40
+
41
+ step_num += 1
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)
48
+ 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
+ end
56
+ end
57
+ apply_diff(step_dir, cur_diff) if cur_diff
58
+ end
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def apply_diff(dir, diff)
65
+ stdin = IO.popen("git --git-dir= apply --directory=#{dir} -", "w")
66
+ stdin.write diff
67
+ stdin.close
68
+ end
69
+ end
70
+
data/lib/leg/commands.rb CHANGED
@@ -4,8 +4,10 @@ end
4
4
 
5
5
  require 'leg/commands/base_command'
6
6
 
7
+ require 'leg/commands/diff'
7
8
  require 'leg/commands/help'
8
9
  require 'leg/commands/pieces'
9
10
  require 'leg/commands/repo'
11
+ require 'leg/commands/undiff'
10
12
  require 'leg/commands/unrepo'
11
13
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oleg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Ruten
@@ -36,9 +36,11 @@ files:
36
36
  - lib/leg/cli.rb
37
37
  - lib/leg/commands.rb
38
38
  - lib/leg/commands/base_command.rb
39
+ - lib/leg/commands/diff.rb
39
40
  - lib/leg/commands/help.rb
40
41
  - lib/leg/commands/pieces.rb
41
42
  - lib/leg/commands/repo.rb
43
+ - lib/leg/commands/undiff.rb
42
44
  - lib/leg/commands/unrepo.rb
43
45
  homepage: https://github.com/yjerem/leg
44
46
  licenses: