rfix 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +38 -0
- data/.gitignore +43 -0
- data/.rspec +2 -0
- data/.rubocop.yml +87 -0
- data/.travis.yml +37 -0
- data/Gemfile +2 -0
- data/Gemfile.base +14 -0
- data/Gemfile.base.lock +172 -0
- data/Gemfile.lock +181 -0
- data/Guardfile +16 -0
- data/LICENSE.txt +21 -0
- data/Makefile +4 -0
- data/README.md +92 -0
- data/Rakefile +27 -0
- data/bin/bundle +114 -0
- data/bin/console +29 -0
- data/bin/guard +29 -0
- data/bin/rake +29 -0
- data/bin/rfix +29 -0
- data/bin/rspec +29 -0
- data/bin/setup +29 -0
- data/ci/Gemfile.rubocop-0.80 +2 -0
- data/ci/Gemfile.rubocop-0.80.lock +170 -0
- data/ci/Gemfile.rubocop-0.81 +2 -0
- data/ci/Gemfile.rubocop-0.81.lock +170 -0
- data/ci/Gemfile.rubocop-0.82 +2 -0
- data/ci/Gemfile.rubocop-0.82.lock +170 -0
- data/ci/Gemfile.rubocop-0.83 +2 -0
- data/ci/Gemfile.rubocop-0.83.lock +168 -0
- data/ci/Gemfile.rubocop-0.84 +2 -0
- data/ci/Gemfile.rubocop-0.84.lock +171 -0
- data/ci/Gemfile.rubocop-0.85 +2 -0
- data/ci/Gemfile.rubocop-0.85.1 +2 -0
- data/ci/Gemfile.rubocop-0.85.1.lock +173 -0
- data/ci/Gemfile.rubocop-0.85.lock +173 -0
- data/exe/rfix +30 -0
- data/lib/rfix.rb +34 -0
- data/lib/rfix/box.rb +112 -0
- data/lib/rfix/branch.rb +31 -0
- data/lib/rfix/branches/base.rb +29 -0
- data/lib/rfix/branches/head.rb +13 -0
- data/lib/rfix/branches/main.rb +34 -0
- data/lib/rfix/branches/name.rb +23 -0
- data/lib/rfix/branches/reference.rb +21 -0
- data/lib/rfix/branches/upstream.rb +13 -0
- data/lib/rfix/cmd.rb +39 -0
- data/lib/rfix/commands/branch.rb +15 -0
- data/lib/rfix/commands/extensions/options.rb +8 -0
- data/lib/rfix/commands/help.rb +7 -0
- data/lib/rfix/commands/helper/args.rb +137 -0
- data/lib/rfix/commands/helper/help.rb +6 -0
- data/lib/rfix/commands/helper/loader.rb +6 -0
- data/lib/rfix/commands/helper/option.rb +0 -0
- data/lib/rfix/commands/helper/params.rb +0 -0
- data/lib/rfix/commands/helper/rubocop.rb +17 -0
- data/lib/rfix/commands/info.rb +30 -0
- data/lib/rfix/commands/lint.rb +23 -0
- data/lib/rfix/commands/local.rb +12 -0
- data/lib/rfix/commands/origin.rb +19 -0
- data/lib/rfix/commands/setup.rb +29 -0
- data/lib/rfix/commands/welcome.rb +24 -0
- data/lib/rfix/deleted.rb +13 -0
- data/lib/rfix/error.rb +2 -0
- data/lib/rfix/extensions/extensions.rb +18 -0
- data/lib/rfix/extensions/offense.rb +78 -0
- data/lib/rfix/extensions/string.rb +8 -0
- data/lib/rfix/file.rb +46 -0
- data/lib/rfix/file_cache.rb +59 -0
- data/lib/rfix/formatter.rb +126 -0
- data/lib/rfix/git_helper.rb +59 -0
- data/lib/rfix/log.rb +131 -0
- data/lib/rfix/no_file.rb +13 -0
- data/lib/rfix/rake/paths.rb +50 -0
- data/lib/rfix/rake/support.rb +75 -0
- data/lib/rfix/repository.rb +204 -0
- data/lib/rfix/rfix.rb +34 -0
- data/lib/rfix/tracked.rb +72 -0
- data/lib/rfix/tracked_file.rb +16 -0
- data/lib/rfix/untracked.rb +13 -0
- data/lib/rfix/version.rb +5 -0
- data/resources/ps.png +0 -0
- data/rfix.gemspec +68 -0
- data/tasks/bump.rake +11 -0
- data/tasks/bundle.rake +17 -0
- data/tasks/complex.rake +54 -0
- data/tasks/execute.rake +38 -0
- data/tasks/libgit2.rake +33 -0
- data/tasks/simple.rake +62 -0
- data/tasks/travis.rake +74 -0
- data/tasks/vendor.rake +34 -0
- metadata +350 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
module Rfix
|
4
|
+
class Branch::Name < Branch::Base
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize(name)
|
8
|
+
@name = name
|
9
|
+
end
|
10
|
+
|
11
|
+
def resolve(with:)
|
12
|
+
unless branch = with.branches[name]
|
13
|
+
raise Branch::UnknownBranchError.new("Could not find branch {{error:#{name}}}")
|
14
|
+
end
|
15
|
+
|
16
|
+
with.lookup(with.merge_base(branch.target_id, with.head.target_id))
|
17
|
+
rescue Rugged::ReferenceError
|
18
|
+
raise Branch::UnknownBranchError.new("Could not find branch {{error:#{name}}}")
|
19
|
+
end
|
20
|
+
|
21
|
+
alias to_s name
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
|
3
|
+
module Rfix
|
4
|
+
class Branch::Reference < Branch::Base
|
5
|
+
attr_reader :reference
|
6
|
+
|
7
|
+
def initialize(reference)
|
8
|
+
@reference = reference
|
9
|
+
end
|
10
|
+
|
11
|
+
def resolve(with:)
|
12
|
+
Branch::Name.new(reference).resolve(with: with)
|
13
|
+
rescue Branch::UnknownBranchError
|
14
|
+
revparse(using: with, ref: reference)
|
15
|
+
rescue Rugged::InvalidError
|
16
|
+
raise Branch::UnknownBranchError.new("Branch with reference {{error:#{reference}}} not found")
|
17
|
+
end
|
18
|
+
|
19
|
+
alias to_s reference
|
20
|
+
end
|
21
|
+
end
|
data/lib/rfix/cmd.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "open3"
|
4
|
+
require "rfix"
|
5
|
+
require "rfix/log"
|
6
|
+
|
7
|
+
module Rfix::Cmd
|
8
|
+
include Rfix::Log
|
9
|
+
|
10
|
+
def cmd(*args, quiet: false)
|
11
|
+
out, err, status = Open3.capture3(*args)
|
12
|
+
box = Rfix::Box.new(out, err, status, args, quiet)
|
13
|
+
return box.stdout if box.success?
|
14
|
+
return yield if block_given?
|
15
|
+
return if quiet
|
16
|
+
|
17
|
+
box.render(color: :red)
|
18
|
+
exit box.exit_status
|
19
|
+
ensure
|
20
|
+
# box.render(debug: false)
|
21
|
+
end
|
22
|
+
|
23
|
+
def cmd_succeeded?(*cmd)
|
24
|
+
Open3.capture2e(*cmd).last.success?
|
25
|
+
end
|
26
|
+
|
27
|
+
def params
|
28
|
+
[
|
29
|
+
"--word-diff-regex=[^[:space:]]",
|
30
|
+
"--no-renames",
|
31
|
+
"--no-merges",
|
32
|
+
"--first-parent",
|
33
|
+
"--diff-filter=AM",
|
34
|
+
"-U0",
|
35
|
+
"--no-color",
|
36
|
+
"-p"
|
37
|
+
]
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
r_args = []
|
2
|
+
|
3
|
+
helper("help", binding)
|
4
|
+
helper("rubocop", binding)
|
5
|
+
helper("args", binding)
|
6
|
+
|
7
|
+
param :branch
|
8
|
+
usage "rfix branch BRANCH [opts] [-p path ..]"
|
9
|
+
option :p, :path, "Path to be passed to RuboCop", argument: :required, multiple: true
|
10
|
+
summary "Fix changes made between HEAD and <branch>"
|
11
|
+
|
12
|
+
run do |opts, args, _cmd|
|
13
|
+
branch = Rfix::Branch::Reference.new(args[:branch])
|
14
|
+
setup(r_args, opts, args, files: opts[:path] || [], reference: branch)
|
15
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
option :r, :root, "{{*}} Project root path", default: Dir.pwd, argument: :required
|
2
|
+
option :b, :"main-branch", "{{*}} Branch to use", default: "master", argument: :required
|
3
|
+
option :l, :limit, "{{*}} Limit number of files", argument: :required, transform: method(:Integer)
|
4
|
+
|
5
|
+
flag nil, :dry, "{{*}} Run in dry mode"
|
6
|
+
flag nil, :untracked, "{{*}} Load untracked files"
|
7
|
+
flag nil, :"clear-cache", "{{*}} Clear Rubocop`s cache"
|
8
|
+
flag nil, :test, "{{*}} Used in tests"
|
9
|
+
|
10
|
+
def validate!(files:)
|
11
|
+
return [] unless files.is_a?(Array)
|
12
|
+
|
13
|
+
files.each do |file|
|
14
|
+
unless File.exist?(file)
|
15
|
+
say_abort "Passed file {{error:#{file}}} does not exist"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
files
|
20
|
+
end
|
21
|
+
|
22
|
+
def setup(r_args = [], opts, _args, files: [], reference:)
|
23
|
+
# files = validate!(files: files)
|
24
|
+
options = RuboCop::Options.new
|
25
|
+
store = RuboCop::ConfigStore.new
|
26
|
+
|
27
|
+
params = {
|
28
|
+
force_exclusion: true,
|
29
|
+
formatters: ["Rfix::Formatter"],
|
30
|
+
auto_correct: true
|
31
|
+
}
|
32
|
+
|
33
|
+
if opts.key?(:format)
|
34
|
+
params.delete(:formatters)
|
35
|
+
end
|
36
|
+
|
37
|
+
if opts.key?(:dry)
|
38
|
+
params[:auto_correct] = false
|
39
|
+
end
|
40
|
+
|
41
|
+
if opts.key?(:test)
|
42
|
+
params.delete(:formatters)
|
43
|
+
params[:format] = "json"
|
44
|
+
params[:cache] = "false"
|
45
|
+
Rfix.test = true
|
46
|
+
|
47
|
+
unless opts.key?(:root)
|
48
|
+
raise "No --root passed with --test"
|
49
|
+
end
|
50
|
+
|
51
|
+
unless opts.key?(:config)
|
52
|
+
raise "No --config passed with --test"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
if opts[:cache] == "false"
|
57
|
+
params[:cache] = "false"
|
58
|
+
end
|
59
|
+
|
60
|
+
begin
|
61
|
+
Rfix.repo = repo = Rfix::Repository.new(
|
62
|
+
root_path: opts[:root],
|
63
|
+
load_untracked: opts[:untracked],
|
64
|
+
reference: reference,
|
65
|
+
paths: files || []
|
66
|
+
)
|
67
|
+
rescue Rugged::RepositoryError => e
|
68
|
+
say_abort e.to_s
|
69
|
+
rescue Rfix::Error => e
|
70
|
+
say_abort e.to_s
|
71
|
+
end
|
72
|
+
|
73
|
+
# RuboCop::ResultCache.cleanup(store, true)
|
74
|
+
|
75
|
+
if opts[:"clear-cache"]
|
76
|
+
RuboCop::ResultCache.cleanup(store, true)
|
77
|
+
params[:cache] = "false"
|
78
|
+
say_debug "Cleared Rubocop`s cache"
|
79
|
+
end
|
80
|
+
|
81
|
+
if block_given?
|
82
|
+
yield(repo, [])
|
83
|
+
end
|
84
|
+
|
85
|
+
begin
|
86
|
+
params2, paths = options.parse(r_args)
|
87
|
+
rescue OptionParser::MissingArgument => e
|
88
|
+
say_abort e.to_s
|
89
|
+
end
|
90
|
+
|
91
|
+
params2.merge!(params)
|
92
|
+
|
93
|
+
begin
|
94
|
+
if config = opts[:config]
|
95
|
+
store.options_config = config
|
96
|
+
elsif root_path = opts[:root]
|
97
|
+
store.for(root_path)
|
98
|
+
end
|
99
|
+
rescue RuboCop::Error => e
|
100
|
+
say_abort e.to_s
|
101
|
+
rescue TypeError => e
|
102
|
+
say_abort e.to_s
|
103
|
+
rescue Psych::SyntaxError => e
|
104
|
+
say_abort e.to_s
|
105
|
+
end
|
106
|
+
|
107
|
+
# unless files.empty?
|
108
|
+
# say "Loading files from {{italic:#{files.join(', ')}}}"
|
109
|
+
# end
|
110
|
+
|
111
|
+
if !files.empty?
|
112
|
+
paths = files
|
113
|
+
elsif paths.empty? && repo.paths.empty?
|
114
|
+
if opts[:format] == "json"
|
115
|
+
prt JSON.pretty_generate({"files": []})
|
116
|
+
exit 0
|
117
|
+
else
|
118
|
+
say_exit "Everything looks good, nothing to lint"
|
119
|
+
end
|
120
|
+
elsif paths.empty?
|
121
|
+
paths = repo.paths
|
122
|
+
end
|
123
|
+
|
124
|
+
if limit = opts[:limit]
|
125
|
+
paths = paths.take(limit)
|
126
|
+
end
|
127
|
+
|
128
|
+
env = RuboCop::CLI::Environment.new(params2, store, paths)
|
129
|
+
|
130
|
+
begin
|
131
|
+
exit RuboCop::CLI::Command::ExecuteRunner.new(env).run
|
132
|
+
rescue RuboCop::Runner::InfiniteCorrectionLoop => e
|
133
|
+
say_abort e.to_s
|
134
|
+
rescue RuboCop::Error => e
|
135
|
+
say_abort e.to_s
|
136
|
+
end
|
137
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
RuboCop::Options.new.opts.instance_eval("@stack", __FILE__, __LINE__).map(&:list).flatten.each do |opt|
|
2
|
+
short = opt.short.map { |arg| arg.delete_prefix("-") }
|
3
|
+
long = opt.long.map { |arg| arg.delete_prefix("--") }
|
4
|
+
|
5
|
+
short.unshift(nil) if opt.short.empty?
|
6
|
+
long.unshift(nil) if opt.long.empty?
|
7
|
+
|
8
|
+
if opt.arg
|
9
|
+
option(*short, *long, opt.desc.join(" "), argument: :optional) do |value|
|
10
|
+
r_args.append(*opt.long, value)
|
11
|
+
end
|
12
|
+
else
|
13
|
+
flag(*short, *long, opt.desc.join(" ")) do
|
14
|
+
r_args.append(*opt.long)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "rbconfig"
|
2
|
+
require "rugged"
|
3
|
+
|
4
|
+
extend Rfix::Log
|
5
|
+
extend Rfix::Cmd
|
6
|
+
|
7
|
+
def git_version
|
8
|
+
cmd("git --version").last.split(/\s+/, 3).last
|
9
|
+
end
|
10
|
+
|
11
|
+
def ruby_version
|
12
|
+
RbConfig::CONFIG["ruby_version"] || "<unknown>"
|
13
|
+
end
|
14
|
+
|
15
|
+
def current_os
|
16
|
+
RbConfig::CONFIG["host_os"] || "<unknown>"
|
17
|
+
end
|
18
|
+
|
19
|
+
helper("help", binding)
|
20
|
+
|
21
|
+
summary "Display runtime dependencies and their version"
|
22
|
+
|
23
|
+
run do |_opts, _args|
|
24
|
+
say "Using RuboCop {{info:#{RuboCop::Version.version}}}"
|
25
|
+
say "Using Rugged {{info:#{Rugged::VERSION}}}"
|
26
|
+
say "Using Rfix {{info:#{Rfix::VERSION}}}"
|
27
|
+
say "Using OS {{info:#{current_os}}}"
|
28
|
+
say "Using Git {{info:#{git_version}}}"
|
29
|
+
say "Using Ruby {{info:#{ruby_version}}}"
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
r_args = []
|
2
|
+
|
3
|
+
helper("help", binding)
|
4
|
+
helper("rubocop", binding)
|
5
|
+
helper("args", binding)
|
6
|
+
|
7
|
+
summary "Lints commits and untracked files not yet pushed to upstream"
|
8
|
+
usage "rfix lint [opts] [path ..]"
|
9
|
+
description "Lint (read-only) files"
|
10
|
+
|
11
|
+
|
12
|
+
run do |opts, args, _cmd|
|
13
|
+
opts[:dry] = true
|
14
|
+
opts[:untracked] = true
|
15
|
+
|
16
|
+
if main = opts[:"main-branch"]
|
17
|
+
branch = Rfix::Branch::Name.new(main)
|
18
|
+
else
|
19
|
+
branch = Rfix::Branch::MAIN
|
20
|
+
end
|
21
|
+
|
22
|
+
setup(r_args, opts, args, files: args.each.to_a, reference: branch)
|
23
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
r_args = []
|
2
|
+
|
3
|
+
helper("help", binding)
|
4
|
+
helper("rubocop", binding)
|
5
|
+
helper("args", binding)
|
6
|
+
|
7
|
+
summary "Auto-fixes commits not yet pushed to upstream"
|
8
|
+
usage "rfix local [opts] [path ..]"
|
9
|
+
|
10
|
+
run do |opts, args, _cmd|
|
11
|
+
setup(r_args, opts, args, files: args.each.to_a, reference: Rfix::Branch::UPSTREAM)
|
12
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
r_args = []
|
2
|
+
|
3
|
+
helper("help", binding)
|
4
|
+
helper("rubocop", binding)
|
5
|
+
helper("args", binding)
|
6
|
+
|
7
|
+
summary "Auto-fixes commits between HEAD and origin branch"
|
8
|
+
usage "rfix origin [opts] [path ..]"
|
9
|
+
|
10
|
+
run do |opts, args, _cmd|
|
11
|
+
if main = opts[:"main-branch"]
|
12
|
+
branch = Rfix::Branch::Name.new(main)
|
13
|
+
else
|
14
|
+
branch = Rfix::Branch::MAIN
|
15
|
+
end
|
16
|
+
|
17
|
+
# say "Using {{red:#{branch}}} as main branch"
|
18
|
+
setup(r_args, opts, args, files: args.each.to_a, reference: branch)
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
helper("help", binding)
|
2
|
+
|
3
|
+
option :r, :root, "{{*}} Project root path", default: Dir.pwd, argument: :required
|
4
|
+
option :b, :"main-branch", "{{*}} Branch to use", argument: :optional
|
5
|
+
|
6
|
+
summary "Sets the default branch for {{command:rfix local}}"
|
7
|
+
|
8
|
+
def set_branch(root_path, branch)
|
9
|
+
Rfix::Branch::Main.set(branch, at: root_path)
|
10
|
+
say "Main branch was set to {{italic:#{branch}}}"
|
11
|
+
end
|
12
|
+
|
13
|
+
run do |opts, _args|
|
14
|
+
if branch = Rfix::Branch::Main.get(at: opts[:root])
|
15
|
+
say "Current main branch set to {{info:#{branch}}}"
|
16
|
+
end
|
17
|
+
|
18
|
+
if branch = opts[:"main-branch"]
|
19
|
+
next set_branch(opts[:root], branch)
|
20
|
+
end
|
21
|
+
|
22
|
+
CLI::UI::Prompt.ask("Which one is your main branch?") do |handler|
|
23
|
+
Rfix::Branch.local(at: opts[:root]).each do |branch|
|
24
|
+
handler.option(branch) do |selection|
|
25
|
+
set_branch(opts[:root], selection)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
r_args = []
|
2
|
+
|
3
|
+
helper("help", binding)
|
4
|
+
|
5
|
+
summary "This is how you get started with {{command:rfix}}"
|
6
|
+
|
7
|
+
run do |_opts, _args, _cmd|
|
8
|
+
indent = " " * 2
|
9
|
+
prt "{{v}} Thank you for installing {{green:rfix v#{Rfix::VERSION}}}!\n"
|
10
|
+
prt ""
|
11
|
+
prt "{{i}} Run {{command:rfix help}} for avalible commands or any of the following to get started:"
|
12
|
+
prt ""
|
13
|
+
prt "#{indent}{{command:$ rfix local}} {{italic:# Auto-fixes commits not yet pushed to upstream}}"
|
14
|
+
prt "#{indent}{{command:$ rfix origin}} {{italic:# Auto-fixes commits between HEAD and origin branch}}"
|
15
|
+
prt "#{indent}{{command:$ rfix lint}} {{italic:# Lints commits and untracked files not yet pushed to upstream}}"
|
16
|
+
prt ""
|
17
|
+
prt "{{*}} {{bold:ProTip:}} Append {{command:--dry}} to run {{command:rfix}} in {{warning:read-only}} mode"
|
18
|
+
prt ""
|
19
|
+
prt "{{i}} {{bold:Issues}} {{italic:https://github.com/oleander/rfix-rb/issues}}"
|
20
|
+
prt "{{i}} {{bold:Readme}} {{italic:https://github.com/oleander/rfix-rb/blob/master/README.md}}"
|
21
|
+
prt "{{i}} {{bold:Travis}} {{italic:https://travis-ci.org/github/oleander/rfix-rb}}"
|
22
|
+
prt ""
|
23
|
+
prt "{{italic:~ Linus}}\n"
|
24
|
+
end
|