rfix 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/main.yml +38 -0
  3. data/.gitignore +43 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +87 -0
  6. data/.travis.yml +37 -0
  7. data/Gemfile +2 -0
  8. data/Gemfile.base +14 -0
  9. data/Gemfile.base.lock +172 -0
  10. data/Gemfile.lock +181 -0
  11. data/Guardfile +16 -0
  12. data/LICENSE.txt +21 -0
  13. data/Makefile +4 -0
  14. data/README.md +92 -0
  15. data/Rakefile +27 -0
  16. data/bin/bundle +114 -0
  17. data/bin/console +29 -0
  18. data/bin/guard +29 -0
  19. data/bin/rake +29 -0
  20. data/bin/rfix +29 -0
  21. data/bin/rspec +29 -0
  22. data/bin/setup +29 -0
  23. data/ci/Gemfile.rubocop-0.80 +2 -0
  24. data/ci/Gemfile.rubocop-0.80.lock +170 -0
  25. data/ci/Gemfile.rubocop-0.81 +2 -0
  26. data/ci/Gemfile.rubocop-0.81.lock +170 -0
  27. data/ci/Gemfile.rubocop-0.82 +2 -0
  28. data/ci/Gemfile.rubocop-0.82.lock +170 -0
  29. data/ci/Gemfile.rubocop-0.83 +2 -0
  30. data/ci/Gemfile.rubocop-0.83.lock +168 -0
  31. data/ci/Gemfile.rubocop-0.84 +2 -0
  32. data/ci/Gemfile.rubocop-0.84.lock +171 -0
  33. data/ci/Gemfile.rubocop-0.85 +2 -0
  34. data/ci/Gemfile.rubocop-0.85.1 +2 -0
  35. data/ci/Gemfile.rubocop-0.85.1.lock +173 -0
  36. data/ci/Gemfile.rubocop-0.85.lock +173 -0
  37. data/exe/rfix +30 -0
  38. data/lib/rfix.rb +34 -0
  39. data/lib/rfix/box.rb +112 -0
  40. data/lib/rfix/branch.rb +31 -0
  41. data/lib/rfix/branches/base.rb +29 -0
  42. data/lib/rfix/branches/head.rb +13 -0
  43. data/lib/rfix/branches/main.rb +34 -0
  44. data/lib/rfix/branches/name.rb +23 -0
  45. data/lib/rfix/branches/reference.rb +21 -0
  46. data/lib/rfix/branches/upstream.rb +13 -0
  47. data/lib/rfix/cmd.rb +39 -0
  48. data/lib/rfix/commands/branch.rb +15 -0
  49. data/lib/rfix/commands/extensions/options.rb +8 -0
  50. data/lib/rfix/commands/help.rb +7 -0
  51. data/lib/rfix/commands/helper/args.rb +137 -0
  52. data/lib/rfix/commands/helper/help.rb +6 -0
  53. data/lib/rfix/commands/helper/loader.rb +6 -0
  54. data/lib/rfix/commands/helper/option.rb +0 -0
  55. data/lib/rfix/commands/helper/params.rb +0 -0
  56. data/lib/rfix/commands/helper/rubocop.rb +17 -0
  57. data/lib/rfix/commands/info.rb +30 -0
  58. data/lib/rfix/commands/lint.rb +23 -0
  59. data/lib/rfix/commands/local.rb +12 -0
  60. data/lib/rfix/commands/origin.rb +19 -0
  61. data/lib/rfix/commands/setup.rb +29 -0
  62. data/lib/rfix/commands/welcome.rb +24 -0
  63. data/lib/rfix/deleted.rb +13 -0
  64. data/lib/rfix/error.rb +2 -0
  65. data/lib/rfix/extensions/extensions.rb +18 -0
  66. data/lib/rfix/extensions/offense.rb +78 -0
  67. data/lib/rfix/extensions/string.rb +8 -0
  68. data/lib/rfix/file.rb +46 -0
  69. data/lib/rfix/file_cache.rb +59 -0
  70. data/lib/rfix/formatter.rb +126 -0
  71. data/lib/rfix/git_helper.rb +59 -0
  72. data/lib/rfix/log.rb +131 -0
  73. data/lib/rfix/no_file.rb +13 -0
  74. data/lib/rfix/rake/paths.rb +50 -0
  75. data/lib/rfix/rake/support.rb +75 -0
  76. data/lib/rfix/repository.rb +204 -0
  77. data/lib/rfix/rfix.rb +34 -0
  78. data/lib/rfix/tracked.rb +72 -0
  79. data/lib/rfix/tracked_file.rb +16 -0
  80. data/lib/rfix/untracked.rb +13 -0
  81. data/lib/rfix/version.rb +5 -0
  82. data/resources/ps.png +0 -0
  83. data/rfix.gemspec +68 -0
  84. data/tasks/bump.rake +11 -0
  85. data/tasks/bundle.rake +17 -0
  86. data/tasks/complex.rake +54 -0
  87. data/tasks/execute.rake +38 -0
  88. data/tasks/libgit2.rake +33 -0
  89. data/tasks/simple.rake +62 -0
  90. data/tasks/travis.rake +74 -0
  91. data/tasks/vendor.rake +34 -0
  92. metadata +350 -0
@@ -0,0 +1,173 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rfix (1.0.20)
5
+ cri (~> 2.15.10)
6
+ listen (~> 3.0)
7
+ rainbow (~> 3.0)
8
+ rouge (~> 3.20)
9
+ rubocop (>= 0.80)
10
+ rugged (~> 1.0.0)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ activesupport (6.0.3.2)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 0.7, < 2)
18
+ minitest (~> 5.1)
19
+ tzinfo (~> 1.1)
20
+ zeitwerk (~> 2.2, >= 2.2.2)
21
+ aruba (1.0.2)
22
+ childprocess (>= 2.0, < 5.0)
23
+ contracts (~> 0.16.0)
24
+ cucumber (>= 2.4, < 5.0)
25
+ ffi (~> 1.9)
26
+ rspec-expectations (~> 3.4)
27
+ thor (~> 1.0)
28
+ ast (2.4.1)
29
+ builder (3.2.4)
30
+ childprocess (4.0.0)
31
+ coderay (1.1.3)
32
+ colorize (0.8.1)
33
+ concurrent-ruby (1.1.6)
34
+ contracts (0.16.0)
35
+ cri (2.15.10)
36
+ cucumber (4.0.0)
37
+ builder (~> 3.2, >= 3.2.3)
38
+ cucumber-core (~> 7.0, >= 7.0.0)
39
+ cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
40
+ cucumber-gherkin (~> 13.0, >= 13.0.0)
41
+ cucumber-html-formatter (~> 6.0, >= 6.0.1)
42
+ cucumber-messages (~> 12.1, >= 12.1.1)
43
+ cucumber-wire (~> 3.0, >= 3.0.0)
44
+ diff-lcs (~> 1.3, >= 1.3)
45
+ multi_test (~> 0.1, >= 0.1.2)
46
+ sys-uname (~> 1.0, >= 1.0.2)
47
+ cucumber-core (7.0.0)
48
+ cucumber-gherkin (~> 13.0, >= 13.0.0)
49
+ cucumber-messages (~> 12.1, >= 12.1.1)
50
+ cucumber-tag-expressions (~> 2.0, >= 2.0.4)
51
+ cucumber-cucumber-expressions (10.2.0)
52
+ cucumber-gherkin (13.0.0)
53
+ cucumber-messages (~> 12.0, >= 12.0.0)
54
+ cucumber-html-formatter (6.0.3)
55
+ cucumber-messages (~> 12.1, >= 12.1.1)
56
+ cucumber-messages (12.1.1)
57
+ protobuf-cucumber (~> 3.10, >= 3.10.8)
58
+ cucumber-tag-expressions (2.0.4)
59
+ cucumber-wire (3.0.0)
60
+ cucumber-core (~> 7.0, >= 7.0.0)
61
+ cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
62
+ cucumber-messages (~> 12.1, >= 12.1.1)
63
+ diff-lcs (1.3)
64
+ faker (2.13.0)
65
+ i18n (>= 1.6, < 2)
66
+ ffi (1.13.1)
67
+ formatador (0.2.5)
68
+ gem-release (2.1.1)
69
+ git (1.7.0)
70
+ rchardet (~> 1.8)
71
+ guard (2.16.2)
72
+ formatador (>= 0.2.4)
73
+ listen (>= 2.7, < 4.0)
74
+ lumberjack (>= 1.0.12, < 2.0)
75
+ nenv (~> 0.1)
76
+ notiffany (~> 0.0)
77
+ pry (>= 0.9.12)
78
+ shellany (~> 0.0)
79
+ thor (>= 0.18.1)
80
+ guard-compat (1.2.1)
81
+ guard-rspec (4.7.3)
82
+ guard (~> 2.1)
83
+ guard-compat (~> 1.1)
84
+ rspec (>= 2.99.0, < 4.0)
85
+ i18n (1.8.3)
86
+ concurrent-ruby (~> 1.0)
87
+ listen (3.2.1)
88
+ rb-fsevent (~> 0.10, >= 0.10.3)
89
+ rb-inotify (~> 0.9, >= 0.9.10)
90
+ lumberjack (1.2.6)
91
+ method_source (1.0.0)
92
+ middleware (0.1.0)
93
+ minitest (5.14.1)
94
+ multi_test (0.1.2)
95
+ nenv (0.3.0)
96
+ notiffany (0.1.3)
97
+ nenv (~> 0.1)
98
+ shellany (~> 0.0)
99
+ parallel (1.19.2)
100
+ parser (2.7.1.4)
101
+ ast (~> 2.4.1)
102
+ protobuf-cucumber (3.10.8)
103
+ activesupport (>= 3.2)
104
+ middleware
105
+ thor
106
+ thread_safe
107
+ pry (0.13.1)
108
+ coderay (~> 1.1)
109
+ method_source (~> 1.0)
110
+ rainbow (3.0.0)
111
+ rake (12.3.3)
112
+ rb-fsevent (0.10.4)
113
+ rb-inotify (0.10.1)
114
+ ffi (~> 1.0)
115
+ rchardet (1.8.0)
116
+ regexp_parser (1.7.1)
117
+ rexml (3.2.4)
118
+ rouge (3.20.0)
119
+ rspec (3.9.0)
120
+ rspec-core (~> 3.9.0)
121
+ rspec-expectations (~> 3.9.0)
122
+ rspec-mocks (~> 3.9.0)
123
+ rspec-core (3.9.2)
124
+ rspec-support (~> 3.9.3)
125
+ rspec-expectations (3.9.2)
126
+ diff-lcs (>= 1.2.0, < 2.0)
127
+ rspec-support (~> 3.9.0)
128
+ rspec-mocks (3.9.1)
129
+ diff-lcs (>= 1.2.0, < 2.0)
130
+ rspec-support (~> 3.9.0)
131
+ rspec-support (3.9.3)
132
+ rubocop (0.85.0)
133
+ parallel (~> 1.10)
134
+ parser (>= 2.7.0.1)
135
+ rainbow (>= 2.2.2, < 4.0)
136
+ regexp_parser (>= 1.7)
137
+ rexml
138
+ rubocop-ast (>= 0.0.3)
139
+ ruby-progressbar (~> 1.7)
140
+ unicode-display_width (>= 1.4.0, < 2.0)
141
+ rubocop-ast (0.0.3)
142
+ parser (>= 2.7.0.1)
143
+ ruby-progressbar (1.10.1)
144
+ rugged (1.0.1)
145
+ shellany (0.0.1)
146
+ sys-uname (1.2.1)
147
+ ffi (>= 1.0.0)
148
+ thor (1.0.1)
149
+ thread_safe (0.3.6)
150
+ tzinfo (1.2.7)
151
+ thread_safe (~> 0.1)
152
+ unicode-display_width (1.7.0)
153
+ zeitwerk (2.3.0)
154
+
155
+ PLATFORMS
156
+ ruby
157
+
158
+ DEPENDENCIES
159
+ aruba (~> 1.0)
160
+ colorize
161
+ faker
162
+ gem-release
163
+ git (~> 1.7.0)
164
+ guard
165
+ guard-rspec
166
+ pry
167
+ rake (~> 12.3)
168
+ rfix!
169
+ rspec (~> 3.0)
170
+ rubocop (= 0.85.0)
171
+
172
+ BUNDLED WITH
173
+ 2.1.4
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "cri"
4
+ require "rfix"
5
+ require "rfix/log"
6
+ require "rubocop"
7
+ require "rfix/extensions/string"
8
+ require "rfix/commands/extensions/options"
9
+ require "rfix/commands/helper/loader"
10
+ require "rfix/branch"
11
+
12
+ include Rfix::Loader
13
+ include Rfix::Log
14
+
15
+ root = Cri::Command.new
16
+
17
+ Dir.glob(File.join(__dir__, "../lib/rfix/commands/*.rb")).each do |command|
18
+ root.add_command(Cri::Command.load_file(command, infer_name: true))
19
+ end
20
+
21
+ begin
22
+ if root.run(ARGV, {}, hard_exit: false)
23
+ exit 0
24
+ else
25
+ prt root.help
26
+ exit 1
27
+ end
28
+ rescue RuntimeError => e
29
+ say_abort e.to_s
30
+ end
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # https://gist.github.com/skanev/9d4bec97d5a6825eaaf6
5
+
6
+ require "cli/ui"
7
+ require "require_all"
8
+ require "rfix/version"
9
+ require "rfix/log"
10
+ require "rfix/cmd"
11
+ require "rfix/repository"
12
+ require "rfix/formatter"
13
+ require "rfix/extensions/extensions"
14
+ require "rfix/extensions/offense"
15
+ require "rfix/branch"
16
+ require "rfix/rfix"
17
+ require "rfix/box"
18
+ require "rfix/error"
19
+
20
+ module Rfix
21
+ module Ext; end
22
+ extend self
23
+ end
24
+
25
+ RuboCop::CommentConfig.prepend(Rfix::Ext::CommentConfig)
26
+ RuboCop::Cop::Offense.prepend(Rfix::Ext::Offense)
27
+
28
+ CLI::UI::StdoutRouter.enable
29
+
30
+ # TODO: Handle cases where color can't be resolved by CLI::UI
31
+ RuboCop::Formatter::SimpleTextFormatter::COLOR_FOR_SEVERITY.each do |severity, color|
32
+ id = RuboCop::Cop::Severity::CODE_TABLE.invert.fetch(severity)
33
+ CLI::UI::Glyph.new(id.to_s, 0x25cf, CLI::UI.resolve_color(color))
34
+ end
@@ -0,0 +1,112 @@
1
+ class Rfix::Box < Struct.new(:out, :err, :status, :args, :quiet)
2
+ include Rfix::Log
3
+
4
+ def render(color: :reset, debug: false)
5
+ return if Rfix.debug? && !debug
6
+
7
+ @render ||= box(title, color: color) do
8
+ margin do
9
+ prt cmd_lines
10
+ end
11
+
12
+ div("{{info:STDOUT}}") do
13
+ prt lines_or_none(stdout)
14
+ end
15
+
16
+ div("{{error:STDERR}}") do
17
+ prt lines_or_none(stderr)
18
+ end
19
+ end
20
+ end
21
+
22
+ def lines_or_none(lines)
23
+ if lines.join.chomp.empty?
24
+ return "{{italic:<none>}}"
25
+ end
26
+
27
+ lines.map(&method(:strip)).join("\n")
28
+ end
29
+
30
+ def title
31
+ "#{quiet_icon}#{icon} #{bin} (#{exit_status}) @ {{italic:#{pwd}}}"
32
+ end
33
+
34
+ def quiet_icon
35
+ return "" unless quiet
36
+
37
+ "{{warning:[silent]}} "
38
+ end
39
+
40
+ def stdout
41
+ @stdout ||= dumpable(out.lines.map(&:chomp))
42
+ end
43
+
44
+ def stderr
45
+ @stderr ||= dumpable(err.lines.map(&:chomp))
46
+ end
47
+
48
+ def dumpable(lines)
49
+ box = self
50
+ lines.tap do
51
+ lines.define_singleton_method(:dump!) do
52
+ tap do
53
+ box.render
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ def icon
60
+ success? ? "{{v}}" : "{{x}}"
61
+ end
62
+
63
+ def success?
64
+ status.success?
65
+ end
66
+
67
+ def bin
68
+ clean_args.first
69
+ end
70
+
71
+ def tail
72
+ clean_args[1..-1]
73
+ end
74
+
75
+ def exit_status
76
+ status.exitstatus
77
+ end
78
+
79
+ def pwd
80
+ if Dir.getwd == Dir.pwd
81
+ return "{{italic:#{Dir.getwd}}}"
82
+ end
83
+
84
+ Dir.getwd.sub(Dir.pwd, "")
85
+ end
86
+
87
+ private
88
+
89
+ def longest_arg
90
+ @longest_arg ||= clean_args.reduce(0) do |acc, arg|
91
+ acc < arg.length ? arg.length : acc
92
+ end
93
+ end
94
+
95
+ def clean_args
96
+ @clean_args ||= args.map(&method(:strip))
97
+ end
98
+
99
+ def rest
100
+ tail.each_slice(2).map do |args|
101
+ args.map do |arg|
102
+ arg.ljust(longest_arg + 5)
103
+ end.join(" ")
104
+ end.map do |tail|
105
+ " {{italic:#{tail}}}"
106
+ end.join("\n")
107
+ end
108
+
109
+ def cmd_lines
110
+ "{{command:$ #{bin} \n#{rest}}}"
111
+ end
112
+ end
@@ -0,0 +1,31 @@
1
+ require "rfix/repository"
2
+ require "rfix/error"
3
+ autoload_rel "branches/*.rb"
4
+
5
+ module Rfix
6
+ module Branch
7
+ class UnknownBranchError < Rfix::Error
8
+ end
9
+
10
+ class NotYetImplementedError < Rfix::Error
11
+ end
12
+ end
13
+ end
14
+
15
+ Pathname(__dir__).glob("branches/*.rb").each(&method(:require))
16
+
17
+ module Rfix
18
+ module Branch
19
+ UPSTREAM = Branch::Upstream.new
20
+ MAIN = Branch::Main.new
21
+ HEAD = Branch::Head.new
22
+
23
+ def self.local(at: Dir.pwd)
24
+ repo(at: at).branches.each_name(:local).sort
25
+ end
26
+
27
+ def self.repo(at:)
28
+ Rugged::Repository.new(at)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ class Rfix::Branch::Base
2
+ def resolve(with:)
3
+ raise Rfix::NotYetImplementedError.new("#resolved")
4
+ end
5
+
6
+ def to_s
7
+ raise Rfix::NotYetImplementedError.new("#to_s")
8
+ end
9
+
10
+ def branch(using:)
11
+ names(using: using).last or raise Rfix::Error.new("No named branch found for {{error:#{self}}}")
12
+ end
13
+
14
+ def names(using:)
15
+ oid = resolve(with: using).oid
16
+ locals = using.branches.each_name(:local).to_a
17
+
18
+ using.branches.select do |branch|
19
+ next false unless locals.include?(branch.name)
20
+ branch.target_id == oid
21
+ end
22
+ end
23
+
24
+ def revparse(using:, ref:)
25
+ using.rev_parse(ref)
26
+ rescue Rugged::InvalidError
27
+ raise Rfix::Branch::UnknownBranchError.new("Could not find reference {{error:#{ref}}}")
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ require_relative "base"
2
+
3
+ module Rfix
4
+ class Branch::Head < Branch::Base
5
+ def resolve(with:)
6
+ with.lookup(with.head.target_id)
7
+ end
8
+
9
+ def to_s
10
+ "HEAD"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,34 @@
1
+ require "rugged"
2
+ require_relative "base"
3
+
4
+ module Rfix
5
+ class Branch::Main < Branch::Base
6
+ KEY = "rfix.main.branch"
7
+
8
+ def resolve(with:)
9
+ unless name = with.config[KEY]
10
+ raise Error.new("Please run {{command:rfix setup}} first")
11
+ end
12
+
13
+ String.new(name).resolve(with: with)
14
+ end
15
+
16
+ def self.set(branch, at: Dir.pwd)
17
+ unless branch.is_a?(String)
18
+ raise Rfix::Error.new("Branch must be a string, got {{error:#{branch.class}}}")
19
+ end
20
+
21
+ check = Branch::Name.new(branch)
22
+ repo = Branch.repo(at: at)
23
+ Branch.repo(at: at).config[KEY] = check.branch(using: repo).name
24
+ end
25
+
26
+ def self.get(at: Dir.pwd)
27
+ Branch.repo(at: at).config[KEY]
28
+ end
29
+
30
+ def to_s
31
+ "configured main branch"
32
+ end
33
+ end
34
+ end