rfix 1.0.15 → 1.1.0.pre.147

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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.rspec +0 -1
  4. data/.rubocop.yml +46 -31
  5. data/.travis.yml +5 -12
  6. data/Gemfile.base +10 -3
  7. data/Gemfile.base.lock +172 -0
  8. data/Gemfile.lock +28 -7
  9. data/Guardfile +1 -1
  10. data/Makefile +4 -13
  11. data/Rakefile +16 -95
  12. data/ci/Gemfile.rubocop-0.80.lock +16 -1
  13. data/ci/Gemfile.rubocop-0.81.lock +16 -1
  14. data/ci/Gemfile.rubocop-0.82.lock +16 -1
  15. data/ci/Gemfile.rubocop-0.83.lock +19 -4
  16. data/ci/Gemfile.rubocop-0.84.lock +19 -4
  17. data/ci/Gemfile.rubocop-0.85.1.lock +19 -4
  18. data/ci/Gemfile.rubocop-0.85.lock +16 -1
  19. data/exe/rfix +18 -144
  20. data/lib/rfix.rb +10 -3
  21. data/lib/rfix/box.rb +112 -0
  22. data/lib/rfix/branch.rb +30 -0
  23. data/lib/rfix/branches/base.rb +29 -0
  24. data/lib/rfix/branches/head.rb +11 -0
  25. data/lib/rfix/branches/main.rb +33 -0
  26. data/lib/rfix/branches/name.rb +21 -0
  27. data/lib/rfix/branches/reference.rb +19 -0
  28. data/lib/rfix/branches/upstream.rb +11 -0
  29. data/lib/rfix/cmd.rb +9 -14
  30. data/lib/rfix/commands/all.rb +26 -0
  31. data/lib/rfix/commands/branch.rb +15 -0
  32. data/lib/rfix/commands/extensions/options.rb +8 -0
  33. data/lib/rfix/commands/help.rb +7 -0
  34. data/lib/rfix/commands/helper/args.rb +137 -0
  35. data/lib/rfix/commands/helper/help.rb +6 -0
  36. data/lib/rfix/commands/helper/loader.rb +6 -0
  37. data/lib/rfix/commands/helper/option.rb +0 -0
  38. data/lib/rfix/commands/helper/params.rb +0 -0
  39. data/lib/rfix/commands/helper/rubocop.rb +17 -0
  40. data/lib/rfix/commands/info.rb +30 -0
  41. data/lib/rfix/commands/lint.rb +23 -0
  42. data/lib/rfix/commands/local.rb +12 -0
  43. data/lib/rfix/commands/origin.rb +19 -0
  44. data/lib/rfix/commands/setup.rb +29 -0
  45. data/lib/rfix/commands/welcome.rb +24 -0
  46. data/lib/rfix/deleted.rb +13 -0
  47. data/lib/rfix/error.rb +2 -0
  48. data/lib/rfix/extensions/extensions.rb +4 -26
  49. data/lib/rfix/extensions/offense.rb +2 -1
  50. data/lib/rfix/extensions/string.rb +8 -0
  51. data/lib/rfix/file.rb +46 -0
  52. data/lib/rfix/file_cache.rb +59 -0
  53. data/lib/rfix/formatter.rb +37 -10
  54. data/lib/rfix/git_helper.rb +13 -1
  55. data/lib/rfix/log.rb +104 -7
  56. data/lib/rfix/no_file.rb +13 -0
  57. data/lib/rfix/rake/paths.rb +50 -0
  58. data/lib/rfix/rake/support.rb +75 -0
  59. data/lib/rfix/repository.rb +201 -0
  60. data/lib/rfix/rfix.rb +7 -198
  61. data/lib/rfix/tracked.rb +76 -0
  62. data/lib/rfix/tracked_file.rb +1 -1
  63. data/lib/rfix/untracked.rb +13 -0
  64. data/lib/rfix/version.rb +1 -1
  65. data/path.rb +7 -0
  66. data/rfix.gemspec +6 -2
  67. data/rugged.rb +206 -0
  68. data/tasks/bump.rake +11 -0
  69. data/tasks/bundle.rake +17 -0
  70. data/tasks/complex.rake +54 -0
  71. data/tasks/simple.rake +58 -0
  72. data/tasks/travis.rake +74 -0
  73. data/tasks/vendor.rake +34 -0
  74. metadata +136 -13
  75. data/file.rb +0 -1
  76. data/lib/rfix/gem_helper.rb +0 -12
  77. data/lib/rfix/git_file.rb +0 -36
  78. data/lib/rfix/rake_helper.rb +0 -56
  79. data/lib/rfix/untracked_file.rb +0 -13
@@ -0,0 +1,76 @@
1
+ require "rfix/no_file"
2
+
3
+ class Rfix::Tracked < Rfix::File
4
+ include Rfix::Log
5
+
6
+ def include?(line)
7
+ set = diff.each_line.to_a.map{ |l| l.new_lineno }.reject { |l| l == -1 }.to_set
8
+ set.include?(line - 1)
9
+ end
10
+
11
+ private
12
+
13
+ # def set
14
+ # return NoFile.new(path) if @set.empty?
15
+ # return @set
16
+ # end
17
+
18
+ # def refresh!
19
+ # @changes = diff.each_line.to_a.map{ |l| l.new_lineno }.to_set
20
+ #
21
+ # if @changes.empty?
22
+ # @changes = NoFile.new(path)
23
+ # end
24
+ # rescue Rugged::TreeError
25
+ # @changed = NoFile.new(path)
26
+ # end
27
+
28
+ # def changes
29
+ # @changes or raise(Rfix::Error, "No changes found: #{self}")
30
+ # end
31
+
32
+ # def needs_update?
33
+ # current_changed_at = changed_at
34
+ # if @changed_at != current_changed_at
35
+ # @changed_at = current_changed_at
36
+ # return true
37
+ # end
38
+ #
39
+ # return false
40
+ # end
41
+
42
+ # def changed_at
43
+ # File.new(absolute_path).ctime
44
+ # end
45
+
46
+ def upstream
47
+ @upstream ||= ref.resolve(with: repo)
48
+ end
49
+
50
+ def head
51
+ @head ||= repo.rev_parse("HEAD")
52
+ end
53
+
54
+ def diff
55
+ upstream.diff(head, {
56
+ include_untracked_content: true,
57
+ # ignore_whitespace_change: true,
58
+ recurse_untracked_dirs: true,
59
+ disable_pathspec_match: false,
60
+ # ignore_whitespace_eol: false,
61
+ include_untracked: true,
62
+ # ignore_whitespace: true,
63
+ ignore_submodules: true,
64
+ include_ignored: false,
65
+ context_lines: 0,
66
+ paths: [path]
67
+ }).tap do |diff|
68
+ diff.find_similar!(
69
+ renames_from_rewrites: true,
70
+ # ignore_whitespace: true,
71
+ renames: true,
72
+ copies: true
73
+ )
74
+ end
75
+ end
76
+ end
@@ -4,7 +4,7 @@ require "rfix/git_file"
4
4
 
5
5
  class Rfix::TrackedFile < Rfix::GitFile
6
6
  def refresh!
7
- @ranges = git("--no-pager", "diff", *params, "#{ref}...HEAD", path)
7
+ @ranges = git("--no-pager", "diff", *params, "#{ref}..HEAD", path)
8
8
  .grep(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/) do
9
9
  Regexp.last_match(1).to_i...(Regexp.last_match(1).to_i + (Regexp.last_match(2) || 1).to_i)
10
10
  end
@@ -0,0 +1,13 @@
1
+ class Rfix::Untracked < Rfix::File
2
+ def include?(_)
3
+ return true
4
+ end
5
+
6
+ def refresh!
7
+ # NOP
8
+ end
9
+
10
+ def inspect
11
+ "<Untracked({{info:#{path}}})>"
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rfix
4
- VERSION = "1.0.15"
4
+ VERSION = "1.1.0"
5
5
  end
data/path.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "jsonpath"
2
+ require "json"
3
+
4
+ json = JSON.parse(File.read("spec/fixtures/rubocop.json"))
5
+ result = JsonPath.new("files[:][?(@.offenses[:].corrected==\"true\")].path").on(json)
6
+
7
+ puts result
@@ -19,8 +19,6 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.authors = ["Linus Oleander"]
21
21
  spec.email = ["linus@oleander.nu"]
22
-
23
- # rubocop:disable Layout/LineLength
24
22
  spec.summary = "RuboCop CLI that only lints and auto-fixes code you committed by utilizing `git-log` and `git-diff`"
25
23
  # rubocop:enable Layout/LineLength
26
24
 
@@ -51,11 +49,17 @@ Gem::Specification.new do |spec|
51
49
 
52
50
  spec.requirements << "git, v2.0+"
53
51
 
52
+ spec.add_runtime_dependency "cri", "~> 2.15.10"
53
+ spec.add_runtime_dependency "listen", "~> 3.0"
54
54
  spec.add_runtime_dependency "rainbow", "~> 3.0"
55
55
  spec.add_runtime_dependency "rouge", "~> 3.20"
56
56
  spec.add_runtime_dependency "rubocop", ">= 0.80"
57
+ spec.add_runtime_dependency "rugged", "~> 1.0.0"
57
58
 
58
59
  spec.add_development_dependency "rspec", "~> 3.0"
59
60
  spec.add_development_dependency "aruba", "~> 1.0"
61
+ spec.add_development_dependency "colorize", "~> 0.8.1"
62
+ spec.add_development_dependency "git", "~> 1.7.0"
60
63
  spec.add_development_dependency "rake", "~> 12.3"
64
+ spec.add_development_dependency "pry", "~> 0.13.1"
61
65
  end
@@ -0,0 +1,206 @@
1
+ require "rugged"
2
+ require "fileutils"
3
+ require "rainbow"
4
+ require "tmpdir"
5
+ require "rfix"
6
+ require 'shellwords'
7
+ require "set"
8
+
9
+ extend Rfix::Log
10
+
11
+ # root_path = Dir.mktmpdir
12
+ # at_exit { FileUtils.remove_dir(root_path) }
13
+
14
+
15
+ # Dir.chdir(root_path) do
16
+ # File.write(".gitignore", "# empty")
17
+ # system "git init"
18
+ # system "git add .gitignore"
19
+ # system "git commit -a -m 'Test'"
20
+ # end
21
+
22
+
23
+ # class Git
24
+ #
25
+ # class Blob < Struct.new(:repo, :tree)
26
+ # def commit(msg)
27
+ # author = {:email=>"tanoku@gmail.com", :time=>Time.now, :name=>"Vicent Mart\303\255"}
28
+ #
29
+ # Rugged::Commit.create(repo,
30
+ # :author => author,
31
+ # :message => msg,
32
+ # :committer => author,
33
+ # :parents => parents,
34
+ # :tree => tree,
35
+ # :update_ref => "HEAD")
36
+ # end
37
+ #
38
+ # def parents
39
+ # repo.empty? ? [] : [ repo.head.target ].compact
40
+ # end
41
+ # end
42
+ #
43
+ # attr_reader :repo
44
+ #
45
+ # def initialize(root_path)
46
+ # @repo = Rugged::Repository.new(root_path)
47
+ # # @repo.index.read_tree(@repo.head.target.tree)
48
+ # # @repo.index.reload
49
+ # # @repo.index.write_tree(@repo)
50
+ # end
51
+ #
52
+ # def blob(params)
53
+ # abort "Must be a hash" unless params.is_a?(Hash)
54
+ # debug("New blob")
55
+ # index = repo.index
56
+ # index.reload
57
+ #
58
+ # params.each do |path, content|
59
+ # oid = repo.write(content, :blob)
60
+ # index.read_tree(repo.head.target.tree)
61
+ # index.add(path: path, oid: oid, mode: 0100644)
62
+ # end
63
+ #
64
+ # Blob.new(repo, index.write_tree(repo))
65
+ # end
66
+ #
67
+ # def has_branch?(name)
68
+ # repo.branches.each_name().include?(name)
69
+ # end
70
+ #
71
+ # def branch(name)
72
+ # debug("Checkout branch #{name}")
73
+ # if branch = repo.branches[name]
74
+ # return repo.checkout(branch)
75
+ # end
76
+ #
77
+ # repo.create_branch(name)
78
+ # end
79
+ #
80
+ # def tag(name)
81
+ # debug("Add tag #{name}")
82
+ # repo.tags.create(name, "HEAD")
83
+ # end
84
+ #
85
+ # def checkout(ref)
86
+ # debug "Checkout ref #{ref}"
87
+ # repo.checkout(ref)
88
+ # end
89
+ #
90
+ # def status
91
+ # debug "-- Get status"
92
+ # repo.status do |file, status|
93
+ # say "#{file} => #{status}"
94
+ # end
95
+ #
96
+ # repo.index.entries.each do |entry|
97
+ # say "Staged: #{entry}"
98
+ # end
99
+ # debug "-- End of status"
100
+ # end
101
+ #
102
+ # def say(msg)
103
+ # puts Rainbow("[LOG]").blue + " #{msg}"
104
+ # end
105
+ #
106
+ # def debug(msg)
107
+ # puts Rainbow("[DEBUG]").red + " #{msg}"
108
+ # end
109
+ #
110
+ # def new_file(file, content)
111
+ # debug "New file #{file}"
112
+ # Dir.chdir(repo.workdir) do
113
+ # File.write(file, content)
114
+ # end
115
+ #
116
+ # file
117
+ # end
118
+ #
119
+ # def add(file)
120
+ # debug "Add file #{file}"
121
+ # index = Rugged::Index.new(file)
122
+ # index.write_tree(repo)
123
+ # Blob.new(repo, index.write_tree(repo))
124
+ # end
125
+ # end
126
+
127
+ # repo = Git.new(root_path)
128
+ # repo.status
129
+ # puts "------"
130
+ # repo.branch("master")
131
+ # repo.tag("v2")
132
+ # repo.branch("mastsdkfjfsd")
133
+ # repo.blob("example.rb" => "This is content").commit("This is my message")
134
+ # repo.status
135
+ # repo.checkout("v2")
136
+ # repo.blob("valid.rb" => "This is content")
137
+ # .commit("This is my message")
138
+ # repo.blob("this.rb" => "This is content").commit("This is my message")
139
+ # file = repo.new_file("valid.rb", "this is content")
140
+ # repo.status
141
+ # blob = repo.add(file)
142
+ # repo.status
143
+ # puts "----"
144
+ # blob.commit("Okay!")
145
+ # repo.status
146
+
147
+ class AFile
148
+ include Rfix::Log
149
+ attr_reader :repo, :path
150
+
151
+ def initialize(path, repo)
152
+ @repo = repo
153
+ @path = Shellwords.escape(path)
154
+ refresh!
155
+ end
156
+
157
+ def include?(line)
158
+ return true unless @changes
159
+ @changes.include?(line)
160
+ end
161
+
162
+ def refresh!
163
+ @changes = changed_lines
164
+ rescue Rugged::TreeError
165
+ @changed = nil
166
+ end
167
+
168
+ private
169
+
170
+ def upstream
171
+ @repo.rev_parse("@{u}:#{@path}")
172
+ end
173
+
174
+ def head
175
+ @repo.rev_parse("HEAD:#{@path}")
176
+ end
177
+
178
+ def diff
179
+ upstream.diff(head)
180
+ end
181
+
182
+ def changed_lines
183
+ diff.each_hunk
184
+ .to_a
185
+ .map(&:lines)
186
+ .flatten
187
+ .map(&:new_lineno)
188
+ .to_set
189
+ end
190
+ end
191
+
192
+ repo = Rugged::Repository.new(".")
193
+
194
+ repo.diff("83800375874a5ebd55b48283cef9245c32103aef", "HEAD").each_delta do |delta|
195
+ pp delta.new_file.fetch(:path)
196
+ end
197
+ # files = `git ls-tree -r master --name-only`.lines.map(&:chomp)
198
+ #
199
+ # result = files.each_with_object({}) do |path, acc|
200
+ # acc[path] = AFile.new(path, repo)
201
+ # end
202
+ #
203
+ # pp reslt
204
+
205
+ # binding.pry
206
+ # repo.branches
@@ -0,0 +1,11 @@
1
+ namespace :gem do
2
+ task :inc do
3
+ sh "gem", "bump", "-c", "-m", "'Bump version to %{version}'"
4
+ end
5
+
6
+ task :amend do
7
+ sh "git commit --amend --no-edit"
8
+ end
9
+
10
+ task bump: [:inc, Bundle::INSTALL, Bundle::ADD, :amend]
11
+ end
@@ -0,0 +1,17 @@
1
+ namespace :bundle do
2
+ task :install do
3
+ gemfiles.each do |gemfile|
4
+ next if gemfile.end_with?(".lock")
5
+
6
+ sh "bundle install", "--gemfile", gemfile, "--jobs 3"
7
+ end
8
+ end
9
+
10
+ namespace :git do
11
+ task :add do
12
+ gemfiles.each do |gemfile|
13
+ sh "git add", gemfile
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,54 @@
1
+ require "tmpdir"
2
+
3
+ namespace :bundle do
4
+ namespace :complex do
5
+ directory Bundle::TMP
6
+
7
+ desc "Build complex bundle"
8
+ task build: [Bundle::Complex::FILE, Bundle::Complex::TEST] do
9
+ say "Complex bundle has been stored @ #{Bundle::Complex::FILE}"
10
+ end
11
+
12
+ desc "Rebuild complex bundle"
13
+ task rebuild: [:flush, Bundle::Complex::BUILD]
14
+
15
+ desc "Remove complex bundle"
16
+ task :flush do
17
+ rm_f Bundle::Complex::FILE
18
+ rm_rf Bundle::Complex::REPO
19
+ end
20
+
21
+ desc "Test repo by cloning to local directory"
22
+ task test: Bundle::Complex::FILE do
23
+ Dir.mktmpdir do |repo|
24
+ sh "git clone", Bundle::Complex::FILE, repo, "--branch master"
25
+ cd repo do
26
+ sh "git rev-list --count HEAD"
27
+ sh "git ls-files"
28
+ sh "git status"
29
+ end
30
+ end
31
+
32
+ say "Finished testing complex bundle"
33
+ end
34
+
35
+ file Bundle::Complex::FILE => Bundle::Complex::REPO do
36
+ cd Bundle::Complex::REPO do
37
+ sh "git bundle create", Bundle::Complex::FILE, "--branches --tags"
38
+ end
39
+ end
40
+
41
+ file Bundle::Complex::REPO do
42
+ sh "git clone", Bundle::Complex::GITHUB, Bundle::Complex::REPO, "--branch", "master"
43
+
44
+ cd Bundle::Complex::REPO do
45
+ sh "git", "reset --hard 27fec8"
46
+
47
+ sh "git config user.email 'not-my@real-email.com'"
48
+ sh "git config user.name 'John Doe'"
49
+
50
+ sh "git tag", Bundle::Complex::TAG
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,58 @@
1
+ namespace :bundle do
2
+ namespace :simple do
3
+ directory Bundle::Simple::REPO
4
+
5
+ desc "Build complex bundle"
6
+ task build: [Bundle::Simple::FILE, Bundle::Simple::TEST] do
7
+ say "Simple bundle has been stored @ #{Bundle::Simple::FILE}"
8
+ end
9
+
10
+ desc "Rebuild complex bundle"
11
+ task rebuild: [:flush, Bundle::Simple::BUILD]
12
+
13
+ desc "Remove complex bundle"
14
+ task :flush do
15
+ rm_f Bundle::Simple::FILE
16
+ rm_rf Bundle::Simple::REPO
17
+ end
18
+
19
+ desc "Test repo by cloning to local directory"
20
+ task test: Bundle::Simple::FILE do
21
+ Dir.mktmpdir do |repo|
22
+ sh "git clone", Bundle::Simple::FILE, repo, "--branch master"
23
+ cd repo do
24
+ sh "git rev-list --count HEAD"
25
+ sh "git ls-files"
26
+ sh "git status"
27
+ end
28
+ end
29
+
30
+ say "Finished testing simple bundle"
31
+ end
32
+
33
+ file Bundle::Simple::FILE => Bundle::Simple::REPO do
34
+ cd Bundle::Simple::REPO do
35
+ sh "git bundle create", Bundle::Simple::FILE, "--branches --tags"
36
+ end
37
+ end
38
+
39
+ file Bundle::Simple::REPO do
40
+ cd Bundle::Simple::REPO do
41
+ touch ".gitignore"
42
+
43
+ sh "git init"
44
+ sh "git add .gitignore"
45
+ sh "git commit -m 'A Commit Message'"
46
+
47
+ sh "git config push.default current"
48
+ sh "git config branch.autosetupmerge always"
49
+ sh "git config branch.autosetuprebase always"
50
+
51
+ sh "git config user.email 'not-my@real-email.com'"
52
+ sh "git config user.name 'John Doe'"
53
+
54
+ sh "git tag", Bundle::Simple::TAG
55
+ end
56
+ end
57
+ end
58
+ end