rfix 1.4.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/rfix +78 -34
- data/lib/rfix.rb +17 -28
- data/lib/rfix/branch.rb +3 -25
- data/lib/rfix/branch/base.rb +27 -0
- data/lib/rfix/branch/head.rb +15 -0
- data/lib/rfix/branch/main.rb +33 -0
- data/lib/rfix/branch/name.rb +21 -0
- data/lib/rfix/branch/reference.rb +15 -0
- data/lib/rfix/branch/upstream.rb +17 -0
- data/lib/rfix/cli/command.rb +19 -0
- data/lib/rfix/cli/command/base.rb +61 -0
- data/lib/rfix/cli/command/branch.rb +13 -0
- data/lib/rfix/cli/command/config.rb +22 -0
- data/lib/rfix/cli/command/extension.rb +25 -0
- data/lib/rfix/cli/command/help.rb +11 -0
- data/lib/rfix/cli/command/info.rb +11 -0
- data/lib/rfix/cli/command/lint.rb +17 -0
- data/lib/rfix/cli/command/local.rb +11 -0
- data/lib/rfix/cli/command/origin.rb +11 -0
- data/lib/rfix/cli/command/setup.rb +11 -0
- data/lib/rfix/error.rb +5 -1
- data/lib/rfix/extension/offense.rb +79 -0
- data/lib/rfix/extension/pastel.rb +11 -0
- data/lib/rfix/extension/string.rb +12 -0
- data/lib/rfix/extension/strings.rb +9 -0
- data/lib/rfix/file.rb +6 -41
- data/lib/rfix/file/base.rb +73 -0
- data/lib/rfix/file/deleted.rb +17 -0
- data/lib/rfix/file/ignored.rb +17 -0
- data/lib/rfix/file/tracked.rb +42 -0
- data/lib/rfix/file/untracked.rb +20 -0
- data/lib/rfix/formatter.rb +125 -86
- data/lib/rfix/highlighter.rb +118 -0
- data/lib/rfix/indicator.rb +19 -0
- data/lib/rfix/log.rb +12 -121
- data/lib/rfix/rake/gemfile.rb +111 -0
- data/lib/rfix/rake/paths.rb +25 -23
- data/lib/rfix/rake/support.rb +72 -57
- data/lib/rfix/repository.rb +114 -164
- data/lib/rfix/types.rb +52 -0
- data/lib/rfix/version.rb +1 -1
- data/rfix.gemspec +28 -38
- data/vendor/dry-cli/CHANGELOG.md +191 -0
- data/vendor/dry-cli/CODEOWNERS +1 -0
- data/vendor/dry-cli/CODE_OF_CONDUCT.md +13 -0
- data/vendor/dry-cli/CONTRIBUTING.md +29 -0
- data/vendor/dry-cli/Gemfile +14 -0
- data/vendor/dry-cli/Gemfile.devtools +18 -0
- data/vendor/dry-cli/LICENSE +20 -0
- data/vendor/dry-cli/README.md +29 -0
- data/vendor/dry-cli/Rakefile +13 -0
- data/vendor/dry-cli/bin/console +15 -0
- data/vendor/dry-cli/bin/setup +8 -0
- data/vendor/dry-cli/changelog.yml +97 -0
- data/vendor/dry-cli/docsite/source/arguments.html.md +57 -0
- data/vendor/dry-cli/docsite/source/callbacks.html.md +51 -0
- data/vendor/dry-cli/docsite/source/commands-with-subcommands-and-params.md +86 -0
- data/vendor/dry-cli/docsite/source/commands.html.md +41 -0
- data/vendor/dry-cli/docsite/source/index.html.md +302 -0
- data/vendor/dry-cli/docsite/source/options.html.md +51 -0
- data/vendor/dry-cli/docsite/source/subcommands.html.md +38 -0
- data/vendor/dry-cli/docsite/source/variadic-arguments.html.md +45 -0
- data/vendor/dry-cli/dry-cli.gemspec +36 -0
- data/vendor/dry-cli/lib/dry/cli.rb +224 -0
- data/vendor/dry-cli/lib/dry/cli/banner.rb +135 -0
- data/vendor/dry-cli/lib/dry/cli/command.rb +387 -0
- data/vendor/dry-cli/lib/dry/cli/command_registry.rb +253 -0
- data/vendor/dry-cli/lib/dry/cli/errors.rb +37 -0
- data/vendor/dry-cli/lib/dry/cli/inflector.rb +17 -0
- data/vendor/dry-cli/lib/dry/cli/inline.rb +75 -0
- data/vendor/dry-cli/lib/dry/cli/option.rb +131 -0
- data/vendor/dry-cli/lib/dry/cli/parser.rb +138 -0
- data/vendor/dry-cli/lib/dry/cli/program_name.rb +21 -0
- data/vendor/dry-cli/lib/dry/cli/registry.rb +338 -0
- data/vendor/dry-cli/lib/dry/cli/usage.rb +94 -0
- data/vendor/dry-cli/lib/dry/cli/version.rb +8 -0
- data/vendor/dry-cli/project.yml +13 -0
- data/vendor/dry-cli/spec/integration/commands_spec.rb +14 -0
- data/vendor/dry-cli/spec/integration/inherited_commands_spec.rb +24 -0
- data/vendor/dry-cli/spec/integration/inline_spec.rb +43 -0
- data/vendor/dry-cli/spec/integration/processes_errors_spec.rb +29 -0
- data/vendor/dry-cli/spec/integration/rendering_spec.rb +31 -0
- data/vendor/dry-cli/spec/integration/single_command_spec.rb +81 -0
- data/vendor/dry-cli/spec/integration/subcommands_spec.rb +60 -0
- data/vendor/dry-cli/spec/integration/third_party_gems_spec.rb +18 -0
- data/vendor/dry-cli/spec/spec_helper.rb +15 -0
- data/vendor/dry-cli/spec/support/coverage.rb +15 -0
- data/vendor/dry-cli/spec/support/files.rb +13 -0
- data/vendor/dry-cli/spec/support/fixtures/based +65 -0
- data/vendor/dry-cli/spec/support/fixtures/baz +9 -0
- data/vendor/dry-cli/spec/support/fixtures/baz_command.rb +19 -0
- data/vendor/dry-cli/spec/support/fixtures/foo +588 -0
- data/vendor/dry-cli/spec/support/fixtures/infinites +31 -0
- data/vendor/dry-cli/spec/support/fixtures/inline +20 -0
- data/vendor/dry-cli/spec/support/fixtures/registry.rb +15 -0
- data/vendor/dry-cli/spec/support/fixtures/shared_commands.rb +596 -0
- data/vendor/dry-cli/spec/support/fixtures/with_block.rb +86 -0
- data/vendor/dry-cli/spec/support/fixtures/with_registry.rb +90 -0
- data/vendor/dry-cli/spec/support/fixtures/with_zero_arity_block.rb +87 -0
- data/vendor/dry-cli/spec/support/helpers.rb +37 -0
- data/vendor/dry-cli/spec/support/path.rb +24 -0
- data/vendor/dry-cli/spec/support/rspec.rb +26 -0
- data/vendor/dry-cli/spec/support/rspec_options.rb +16 -0
- data/vendor/dry-cli/spec/support/shared_examples/commands.rb +300 -0
- data/vendor/dry-cli/spec/support/shared_examples/inherited_commands.rb +197 -0
- data/vendor/dry-cli/spec/support/shared_examples/rendering.rb +181 -0
- data/vendor/dry-cli/spec/support/shared_examples/subcommands.rb +226 -0
- data/vendor/dry-cli/spec/support/shared_examples/third_party_gems.rb +49 -0
- data/vendor/dry-cli/spec/support/warnings.rb +10 -0
- data/vendor/dry-cli/spec/unit/dry/cli/cli_spec.rb +123 -0
- data/vendor/dry-cli/spec/unit/dry/cli/inflector_spec.rb +26 -0
- data/vendor/dry-cli/spec/unit/dry/cli/registry_spec.rb +78 -0
- data/vendor/dry-cli/spec/unit/dry/cli/version_spec.rb +7 -0
- data/vendor/strings-ansi/CHANGELOG.md +24 -0
- data/vendor/strings-ansi/CODE_OF_CONDUCT.md +74 -0
- data/vendor/strings-ansi/Gemfile +11 -0
- data/{LICENSE.txt → vendor/strings-ansi/LICENSE.txt} +1 -1
- data/vendor/strings-ansi/README.md +155 -0
- data/vendor/strings-ansi/Rakefile +8 -0
- data/vendor/strings-ansi/appveyor.yml +32 -0
- data/vendor/strings-ansi/bin/console +14 -0
- data/vendor/strings-ansi/bin/setup +8 -0
- data/vendor/strings-ansi/lib/strings-ansi.rb +1 -0
- data/vendor/strings-ansi/lib/strings/ansi.rb +84 -0
- data/vendor/strings-ansi/lib/strings/ansi/extensions.rb +23 -0
- data/vendor/strings-ansi/lib/strings/ansi/version.rb +7 -0
- data/vendor/strings-ansi/spec/fixtures/ansi_codes.yaml +194 -0
- data/vendor/strings-ansi/spec/spec_helper.rb +51 -0
- data/vendor/strings-ansi/spec/unit/ansi_spec.rb +15 -0
- data/vendor/strings-ansi/spec/unit/extensions_spec.rb +19 -0
- data/vendor/strings-ansi/spec/unit/only_ansi_spec.rb +36 -0
- data/vendor/strings-ansi/spec/unit/sanitize_spec.rb +53 -0
- data/vendor/strings-ansi/strings-ansi.gemspec +34 -0
- data/vendor/strings-ansi/tasks/console.rake +11 -0
- data/vendor/strings-ansi/tasks/coverage.rake +11 -0
- data/vendor/strings-ansi/tasks/spec.rake +29 -0
- metadata +274 -188
- data/.github/workflows/main.yml +0 -26
- data/.gitignore +0 -43
- data/.rspec +0 -2
- data/.rubocop.yml +0 -87
- data/.travis.yml +0 -35
- data/Gemfile +0 -2
- data/Gemfile.base +0 -14
- data/Gemfile.base.lock +0 -172
- data/Gemfile.lock +0 -188
- data/Guardfile +0 -16
- data/Makefile +0 -12
- data/README.md +0 -85
- data/Rakefile +0 -31
- data/bin/bundle +0 -114
- data/bin/console +0 -29
- data/bin/guard +0 -29
- data/bin/rake +0 -29
- data/bin/rfix +0 -29
- data/bin/rspec +0 -29
- data/bin/setup +0 -29
- data/ci/Gemfile.rubocop-0.80 +0 -2
- data/ci/Gemfile.rubocop-0.80.lock +0 -170
- data/ci/Gemfile.rubocop-0.81 +0 -2
- data/ci/Gemfile.rubocop-0.81.lock +0 -170
- data/ci/Gemfile.rubocop-0.82 +0 -2
- data/ci/Gemfile.rubocop-0.82.lock +0 -170
- data/ci/Gemfile.rubocop-0.83 +0 -2
- data/ci/Gemfile.rubocop-0.83.lock +0 -168
- data/ci/Gemfile.rubocop-0.84 +0 -2
- data/ci/Gemfile.rubocop-0.84.lock +0 -171
- data/ci/Gemfile.rubocop-0.85 +0 -2
- data/ci/Gemfile.rubocop-0.85.1 +0 -2
- data/ci/Gemfile.rubocop-0.85.1.lock +0 -173
- data/ci/Gemfile.rubocop-0.85.lock +0 -173
- data/lib/rfix/box.rb +0 -112
- data/lib/rfix/branches/base.rb +0 -15
- data/lib/rfix/branches/head.rb +0 -13
- data/lib/rfix/branches/main.rb +0 -28
- data/lib/rfix/branches/name.rb +0 -23
- data/lib/rfix/branches/reference.rb +0 -21
- data/lib/rfix/branches/upstream.rb +0 -13
- data/lib/rfix/cmd.rb +0 -39
- data/lib/rfix/commands/branch.rb +0 -15
- data/lib/rfix/commands/extensions/options.rb +0 -8
- data/lib/rfix/commands/help.rb +0 -7
- data/lib/rfix/commands/helper/args.rb +0 -141
- data/lib/rfix/commands/helper/help.rb +0 -6
- data/lib/rfix/commands/helper/loader.rb +0 -6
- 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 +0 -17
- data/lib/rfix/commands/info.rb +0 -30
- data/lib/rfix/commands/lint.rb +0 -22
- data/lib/rfix/commands/local.rb +0 -12
- data/lib/rfix/commands/origin.rb +0 -19
- data/lib/rfix/commands/setup.rb +0 -29
- data/lib/rfix/commands/welcome.rb +0 -24
- data/lib/rfix/deleted.rb +0 -13
- data/lib/rfix/extensions/extensions.rb +0 -18
- data/lib/rfix/extensions/offense.rb +0 -78
- data/lib/rfix/extensions/string.rb +0 -8
- data/lib/rfix/file_cache.rb +0 -59
- data/lib/rfix/git_helper.rb +0 -59
- data/lib/rfix/indentation.rb +0 -39
- data/lib/rfix/loader/bundler.rb +0 -37
- data/lib/rfix/loader/env.rb +0 -33
- data/lib/rfix/loader/spec.rb +0 -41
- data/lib/rfix/no_file.rb +0 -13
- data/lib/rfix/rfix.rb +0 -34
- data/lib/rfix/tracked.rb +0 -72
- data/lib/rfix/tracked_file.rb +0 -16
- data/lib/rfix/untracked.rb +0 -13
- data/resources/ps.png +0 -0
- data/tasks/bump.rake +0 -11
- data/tasks/bundle.rake +0 -17
- data/tasks/complex.rake +0 -54
- data/tasks/execute.rake +0 -38
- data/tasks/libgit2.rake +0 -33
- data/tasks/simple.rake +0 -62
- data/tasks/travis.rake +0 -74
- data/tasks/vendor.rake +0 -34
@@ -0,0 +1,111 @@
|
|
1
|
+
require "dry/types"
|
2
|
+
require "dry/struct"
|
3
|
+
require "dry/logic"
|
4
|
+
|
5
|
+
module Rfix
|
6
|
+
module Rake
|
7
|
+
Dry::Types.define_builder(:not) do |type|
|
8
|
+
Dry::Types::Constrained.new(type.lax, rule: Dry::Logic::Operations::Negation.new(type.rule))
|
9
|
+
end
|
10
|
+
|
11
|
+
class Gemfile < Dry::Struct
|
12
|
+
include Dry::Core::Constants, FileUtils
|
13
|
+
|
14
|
+
module Types
|
15
|
+
include Dry::Types()
|
16
|
+
|
17
|
+
module Version
|
18
|
+
AST = Types::String.enum("0.84")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
attribute :root_path, Types::Instance(Pathname)
|
23
|
+
attribute :version, Types::Version::AST.not
|
24
|
+
|
25
|
+
class AST < self
|
26
|
+
attribute :version, Types::Version::AST
|
27
|
+
|
28
|
+
def content
|
29
|
+
[super, 'gem "rubocop-ast", "< 0.7"'].join("\n")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
FORMAT = "Gemfile.rubocop-%s%s"
|
34
|
+
VERSIONS = [
|
35
|
+
'0.82',
|
36
|
+
'0.83',
|
37
|
+
'0.84',
|
38
|
+
'0.92',
|
39
|
+
'0.93',
|
40
|
+
'1.0.0',
|
41
|
+
'1.7.0',
|
42
|
+
'1.5.0',
|
43
|
+
'1.5.1',
|
44
|
+
'1.5.2',
|
45
|
+
'1.6.1',
|
46
|
+
'1.8.1',
|
47
|
+
'1.8.0',
|
48
|
+
'1.9.0',
|
49
|
+
'1.10.0',
|
50
|
+
'1.11.0',
|
51
|
+
'1.12.0',
|
52
|
+
'1.12.1',
|
53
|
+
'1.13.0'
|
54
|
+
]
|
55
|
+
|
56
|
+
def self.call(*args, **kwargs, &block)
|
57
|
+
(self | AST).call(*args, **kwargs, &block)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.files(root_path)
|
61
|
+
VERSIONS.map do |version|
|
62
|
+
Gemfile.call(root_path: root_path, version: version)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def call
|
67
|
+
puts "Working with #{version}"
|
68
|
+
|
69
|
+
gemfile.write(content)
|
70
|
+
|
71
|
+
if lockfile.exist?
|
72
|
+
lockfile.delete
|
73
|
+
end
|
74
|
+
|
75
|
+
bundle_lock
|
76
|
+
puts "Finished with #{version}"
|
77
|
+
end
|
78
|
+
|
79
|
+
def bundle_lock
|
80
|
+
sh *lock_args
|
81
|
+
rescue RuntimeError
|
82
|
+
sh *lock_args[0..-2]
|
83
|
+
end
|
84
|
+
|
85
|
+
def lock_args
|
86
|
+
["bundle", "lock", "--gemfile", gemfile.to_path, "--local"]
|
87
|
+
end
|
88
|
+
|
89
|
+
def to_s
|
90
|
+
gemfile.to_s
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def gemfile
|
96
|
+
root_path.join(FORMAT % [version, EMPTY_STRING])
|
97
|
+
end
|
98
|
+
|
99
|
+
def lockfile
|
100
|
+
root_path.join(FORMAT % [version, ".lock"])
|
101
|
+
end
|
102
|
+
|
103
|
+
def content
|
104
|
+
<<~GEMFILE
|
105
|
+
eval_gemfile("../Gemfile")
|
106
|
+
gem "rubocop", "#{version}"
|
107
|
+
GEMFILE
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/lib/rfix/rake/paths.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Travis
|
2
|
-
SETUP = "travis:setup"
|
3
|
-
INSTALL = "travis:install"
|
4
|
-
TASKS = "travis:tasks:all"
|
5
|
-
GIT = "travis:git:config"
|
4
|
+
SETUP = "travis:setup"
|
5
|
+
INSTALL = "travis:install"
|
6
|
+
TASKS = "travis:tasks:all"
|
7
|
+
GIT = "travis:git:config"
|
6
8
|
end
|
7
9
|
|
8
10
|
module Bundle
|
9
|
-
INSTALL = "bundle:install"
|
10
|
-
ADD = "bundle:git:add"
|
11
|
-
TAG = "rally-point"
|
12
|
-
REBUILD = "bundle:rebuild"
|
13
|
-
BUILD = "bundle:build"
|
11
|
+
INSTALL = "bundle:install"
|
12
|
+
ADD = "bundle:git:add"
|
13
|
+
TAG = "rally-point"
|
14
|
+
REBUILD = "bundle:rebuild"
|
15
|
+
BUILD = "bundle:build"
|
14
16
|
ROOT = Dir.getwd
|
15
17
|
CONFIG = File.join(ROOT, ".rubocop.yml")
|
16
18
|
DIR = File.join(ROOT, "spec/fixtures")
|
@@ -19,21 +21,21 @@ module Bundle
|
|
19
21
|
module Simple
|
20
22
|
FILE = File.join(DIR, "simple.bundle")
|
21
23
|
REPO = File.join(TMP, "simple")
|
22
|
-
REBUILD = "bundle:simple:rebuild"
|
23
|
-
BUILD = "bundle:simple:build"
|
24
|
-
FLUSH = "bundle:simple:flush"
|
25
|
-
TEST = "bundle:simple:test"
|
24
|
+
REBUILD = "bundle:simple:rebuild"
|
25
|
+
BUILD = "bundle:simple:build"
|
26
|
+
FLUSH = "bundle:simple:flush"
|
27
|
+
TEST = "bundle:simple:test"
|
26
28
|
TAG = Bundle::TAG
|
27
29
|
end
|
28
30
|
|
29
31
|
module Complex
|
30
32
|
FILE = File.join(DIR, "complex.bundle")
|
31
33
|
REPO = File.join(TMP, "complex")
|
32
|
-
GITHUB = "https://github.com/oleander/git-fame-rb"
|
33
|
-
REBUILD = "bundle:complex:rebuild"
|
34
|
-
BUILD = "bundle:complex:build"
|
35
|
-
FLUSH = "bundle:complex:flush"
|
36
|
-
TEST = "bundle:complex:test"
|
34
|
+
GITHUB = "https://github.com/oleander/git-fame-rb"
|
35
|
+
REBUILD = "bundle:complex:rebuild"
|
36
|
+
BUILD = "bundle:complex:build"
|
37
|
+
FLUSH = "bundle:complex:flush"
|
38
|
+
TEST = "bundle:complex:test"
|
37
39
|
TAG = Bundle::TAG
|
38
40
|
end
|
39
41
|
end
|
@@ -42,9 +44,9 @@ module Vendor
|
|
42
44
|
ROOT = File.expand_path(File.join(__dir__, "../../.."))
|
43
45
|
DIR = File.join(ROOT, "vendor/shopify")
|
44
46
|
REPO = File.join(DIR, "cli-ui")
|
45
|
-
GITHUB = "https://github.com/shopify/cli-ui"
|
46
|
-
START = "
|
47
|
-
BUILD = "vendor:shopify:build"
|
48
|
-
REBUILD = "vendor:shopify:rebuild"
|
49
|
-
TEST = "vendor:shopify:test"
|
47
|
+
GITHUB = "https://github.com/shopify/cli-ui"
|
48
|
+
START = "6058c301bb144c2f33f7910734d08b1490ed8112"
|
49
|
+
BUILD = "vendor:shopify:build"
|
50
|
+
REBUILD = "vendor:shopify:rebuild"
|
51
|
+
TEST = "vendor:shopify:test"
|
50
52
|
end
|
data/lib/rfix/rake/support.rb
CHANGED
@@ -1,75 +1,90 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rainbow/ext/string"
|
3
4
|
require "shellwords"
|
5
|
+
require "fileutils"
|
4
6
|
|
5
|
-
module Rfix
|
6
|
-
|
7
|
+
module Rfix
|
8
|
+
module Rake
|
9
|
+
module Support
|
10
|
+
class Utils
|
11
|
+
include FileUtils
|
12
|
+
end
|
7
13
|
|
8
|
-
|
9
|
-
|
10
|
-
alias _rm_rf rm_rf
|
11
|
-
alias _rm_f rm_f
|
12
|
-
alias _mkdir_p mkdir_p
|
13
|
-
alias _chdir chdir
|
14
|
+
def self.extended(base)
|
15
|
+
super
|
14
16
|
|
15
|
-
|
16
|
-
Dir["Gemfile*", "ci/Gemfile*"]
|
17
|
-
end
|
17
|
+
utils = Utils.new
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
%i[cd sh rm_rf rm_f rm mkdir_p chdir].each do |name|
|
20
|
+
base.define_singleton_method("_#{name}".to_sym, &utils.method(name))
|
21
|
+
end
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
_sh(*args)
|
27
|
-
end
|
24
|
+
def gemfiles
|
25
|
+
Dir["Gemfile*", "ci/Gemfile*"]
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
28
|
+
def say(msg)
|
29
|
+
warn "#{'==>'.color(:blue)} #{to_relative(msg).italic}"
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
32
|
+
def directory(*args)
|
33
|
+
mkdir_p args
|
34
|
+
end
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
def sh(*args)
|
37
|
+
args = args.map(&:to_s).map(&:shellsplit).flatten
|
38
|
+
colorize args
|
39
|
+
_sh(*args)
|
40
|
+
end
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
def chdir(*args, &block)
|
43
|
+
colorize :cd, args
|
44
|
+
_chdir(*args, &block)
|
45
|
+
end
|
48
46
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
def rm_rf(*args)
|
48
|
+
colorize :rm, args
|
49
|
+
_rm_rf(*args)
|
50
|
+
end
|
53
51
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
52
|
+
def rm_f(*args)
|
53
|
+
colorize :rm, args
|
54
|
+
_rm_f(*args)
|
55
|
+
end
|
60
56
|
|
61
|
-
|
57
|
+
def cd(*args, &block)
|
58
|
+
colorize :cd, args
|
59
|
+
_cd(*args, &block)
|
60
|
+
end
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
def mkdir_p(*args)
|
63
|
+
colorize :mkdir, args
|
64
|
+
_mkdir_p(*args)
|
65
|
+
end
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
def clone_and_run(&block)
|
68
|
+
Dir.mktmpdir do |repo|
|
69
|
+
sh "git clone", Bundle::Complex::FILE, repo, "--branch", "master"
|
70
|
+
Dir.chdir(repo) { block.call(repo) }
|
71
|
+
end
|
72
|
+
end
|
70
73
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
+
private
|
75
|
+
|
76
|
+
def current_path
|
77
|
+
::File.join(Dir.getwd, "/")
|
78
|
+
end
|
79
|
+
|
80
|
+
def to_relative(path)
|
81
|
+
path.to_s.gsub(current_path, "")
|
82
|
+
end
|
83
|
+
|
84
|
+
def colorize(*args)
|
85
|
+
head, *tail = args.flatten.map(&method(:to_relative))
|
86
|
+
say [head.color(:yellow), tail.join(" ").italic].join(" ")
|
87
|
+
end
|
88
|
+
end
|
74
89
|
end
|
75
90
|
end
|
data/lib/rfix/repository.rb
CHANGED
@@ -1,202 +1,152 @@
|
|
1
|
-
|
2
|
-
require "rfix/file"
|
3
|
-
require "rfix/file_cache"
|
4
|
-
require "rfix/untracked"
|
5
|
-
require "rfix/tracked"
|
6
|
-
|
7
|
-
class Rfix::Repository
|
8
|
-
include Rfix::Log
|
9
|
-
attr_reader :files, :repo
|
10
|
-
|
11
|
-
def initialize(root_path:, load_untracked: false, reference: Rfix::Branch::HEAD, paths: [])
|
12
|
-
unless File.exist?(root_path)
|
13
|
-
raise Rfix::Error, "#{root_path} does not exist"
|
14
|
-
end
|
15
|
-
|
16
|
-
unless Pathname.new(root_path).absolute?
|
17
|
-
raise Rfix::Error, "#{root_path} is not absolute"
|
18
|
-
end
|
19
|
-
|
20
|
-
unless reference.is_a?(Rfix::Branch::Base)
|
21
|
-
raise Rfix::Error, "Need Branch::Base, got {{error:#{reference.class}}}"
|
22
|
-
end
|
1
|
+
# frozen_string_literal: true
|
23
2
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
3
|
+
require "active_support/core_ext/module/delegation"
|
4
|
+
require "dry/core/constants"
|
5
|
+
require "dry/core/memoizable"
|
6
|
+
require "dry/struct"
|
7
|
+
require "rugged"
|
29
8
|
|
30
|
-
|
31
|
-
|
9
|
+
module Rfix
|
10
|
+
class Repository < Dry::Struct
|
11
|
+
include Dry::Core::Constants
|
12
|
+
include Log
|
32
13
|
|
33
|
-
|
34
|
-
@load_untracked
|
35
|
-
end
|
14
|
+
attribute :repository, Types.Instance(Rugged::Repository)
|
36
15
|
|
37
|
-
|
38
|
-
!!@reference
|
39
|
-
end
|
16
|
+
attribute :reference, Types.Instance(Branch::Base)
|
40
17
|
|
41
|
-
|
18
|
+
delegate :head, :branches, :workdir, :rev_parse, :diff_workdir, to: :repository
|
42
19
|
|
43
|
-
|
44
|
-
|
45
|
-
|
20
|
+
OPTIONS = {
|
21
|
+
include_untracked_content: true,
|
22
|
+
ignore_whitespace_change: false,
|
23
|
+
recurse_untracked_dirs: true,
|
24
|
+
ignore_whitespace_eol: false,
|
25
|
+
include_unmodified: true,
|
26
|
+
include_untracked: true,
|
27
|
+
ignore_submodules: true,
|
28
|
+
include_ignored: false,
|
29
|
+
context_lines: 0
|
30
|
+
}.freeze
|
46
31
|
|
47
|
-
|
48
|
-
|
32
|
+
def initialize(*)
|
33
|
+
super
|
34
|
+
call
|
35
|
+
end
|
49
36
|
|
50
|
-
|
51
|
-
|
37
|
+
def origin
|
38
|
+
reference.resolve
|
52
39
|
end
|
53
40
|
|
54
|
-
|
55
|
-
|
56
|
-
|
41
|
+
def status(found = EMPTY_HASH.dup)
|
42
|
+
@status ||= begin
|
43
|
+
repository.status do |path, statuses|
|
44
|
+
statuses.each do |status|
|
45
|
+
(found[path] ||= []) << status
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
if repository.head_unborn?
|
50
|
+
return found
|
51
|
+
end
|
52
|
+
|
53
|
+
origin.diff_workdir(**OPTIONS.dup).tap do |diff|
|
54
|
+
diff.find_similar!(
|
55
|
+
renames_from_rewrites: true,
|
56
|
+
renames: true,
|
57
|
+
copies: true
|
58
|
+
)
|
59
|
+
end.each_delta.each_with_object(found) do |delta, acc|
|
60
|
+
(acc[delta.new_file[:path]] ||= []) << delta.status
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
57
64
|
|
58
|
-
|
59
|
-
|
60
|
-
|
65
|
+
def call
|
66
|
+
status.each do |path, statuses|
|
67
|
+
build(path, statuses)
|
68
|
+
end
|
69
|
+
end
|
61
70
|
|
62
|
-
|
63
|
-
|
64
|
-
|
71
|
+
def path
|
72
|
+
Pathname(workdir)
|
73
|
+
end
|
65
74
|
|
66
|
-
|
67
|
-
|
68
|
-
|
75
|
+
# @path [String]
|
76
|
+
def refresh!(*)
|
77
|
+
# NOP
|
78
|
+
end
|
69
79
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
80
|
+
# @path [String]
|
81
|
+
# @line [Integer]
|
82
|
+
# @return Bool
|
83
|
+
def include?(path, line)
|
84
|
+
get(path).include?(line)
|
85
|
+
rescue KeyError
|
86
|
+
false
|
87
|
+
end
|
75
88
|
|
76
|
-
|
77
|
-
|
78
|
-
|
89
|
+
def skipped
|
90
|
+
ignored + deleted
|
91
|
+
end
|
79
92
|
|
80
|
-
|
81
|
-
|
82
|
-
|
93
|
+
def tracked
|
94
|
+
files.values.select(&:tracked?)
|
95
|
+
end
|
83
96
|
|
84
|
-
|
85
|
-
|
86
|
-
|
97
|
+
def ignored
|
98
|
+
files.values.select(&:ignored?)
|
99
|
+
end
|
87
100
|
|
88
|
-
|
89
|
-
|
90
|
-
|
101
|
+
def untracked
|
102
|
+
files.values.select(&:untracked?)
|
103
|
+
end
|
91
104
|
|
92
|
-
|
105
|
+
def deleted
|
106
|
+
files.values.select(&:deleted?)
|
107
|
+
end
|
93
108
|
|
94
|
-
|
95
|
-
|
96
|
-
# ignore_whitespace_change: true,
|
97
|
-
include_untracked_content: true,
|
98
|
-
recurse_untracked_dirs: true,
|
99
|
-
# ignore_whitespace_eol: true,
|
100
|
-
include_unmodified: false,
|
101
|
-
include_untracked: true,
|
102
|
-
ignore_submodules: true,
|
103
|
-
# ignore_whitespace: true,
|
104
|
-
include_ignored: false,
|
105
|
-
context_lines: 0
|
106
|
-
}
|
107
|
-
|
108
|
-
unless @paths.empty?
|
109
|
-
say_debug("Use @paths #{@paths.join(', ')}")
|
110
|
-
params[:disable_pathspec_match] = false
|
111
|
-
params[:paths] = @paths
|
112
|
-
end
|
113
|
-
|
114
|
-
say_debug("Run diff on {{info:#{reference}}}")
|
115
|
-
upstream.diff(head, **params).tap do |diff|
|
116
|
-
diff.find_similar!(
|
117
|
-
renames_from_rewrites: true,
|
118
|
-
renames: true,
|
119
|
-
copies: true
|
120
|
-
)
|
121
|
-
end.each_delta do |delta|
|
122
|
-
path = delta.new_file.fetch(:path)
|
123
|
-
say_debug("Found #{path} while diff")
|
124
|
-
try_store(path, [delta.status])
|
125
|
-
end
|
126
|
-
rescue Rugged::ReferenceError
|
127
|
-
abort_box($ERROR_INFO.to_s) do
|
128
|
-
prt "Reference {{error:#{reference}}} cannot be found in repository"
|
129
|
-
end
|
130
|
-
rescue Rugged::ConfigError
|
131
|
-
abort_box($ERROR_INFO.to_s) do
|
132
|
-
prt "No upstream branch set for {{error:#{current_branch}}}"
|
133
|
-
end
|
134
|
-
rescue TypeError
|
135
|
-
abort_box($ERROR_INFO.to_s) do
|
136
|
-
prt "Reference {{error:#{reference}}} is not pointing to a tree or commit"
|
109
|
+
def permitted
|
110
|
+
untracked + tracked
|
137
111
|
end
|
138
|
-
end
|
139
112
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
113
|
+
def to_s
|
114
|
+
options = {
|
115
|
+
untracked: untracked.map(&:basename).join(", "),
|
116
|
+
tracked: tracked.map(&:basename).join(", "),
|
117
|
+
ignored: ignored.map(&:basename).join(", "),
|
118
|
+
deleted: deleted.map(&:basename).join(", ")
|
119
|
+
}
|
144
120
|
|
145
|
-
|
146
|
-
# - +:index_new+: the file is new in the index
|
147
|
-
# - +:index_modified+: the file has been modified in the index
|
148
|
-
# - +:index_deleted+: the file has been deleted from the index
|
149
|
-
# - +:worktree_new+: the file is new in the working directory
|
150
|
-
# - +:worktree_modified+: the file has been modified in the working directory
|
151
|
-
# - +:worktree_deleted+: the file has been deleted from the working directory
|
152
|
-
|
153
|
-
MODIFIED = [:modified, :worktree_modified, :index_modified].freeze
|
154
|
-
IGNORED = [:ignored].freeze
|
155
|
-
STAGED = [:added, :index_new].freeze
|
156
|
-
UNTRACKED = [:worktree_new, :untracked].freeze
|
157
|
-
COPIED = [:copied].freeze
|
158
|
-
DELETED = [:deleted, :worktree_deleted, :index_deleted].freeze
|
159
|
-
RENAMED = [:renamed].freeze
|
160
|
-
|
161
|
-
SKIP = [*DELETED, *RENAMED, *COPIED, *IGNORED].freeze
|
162
|
-
ACCEPT = [*MODIFIED].freeze
|
163
|
-
|
164
|
-
def load_untracked!
|
165
|
-
repo.status do |path, status|
|
166
|
-
try_store(path, status)
|
121
|
+
"Repository<Untracked: %<untracked>s, Tracked: %<tracked>s, Ignored: %<ignored>s, Deleted: %<deleted>s>" % options
|
167
122
|
end
|
168
|
-
end
|
169
123
|
|
170
|
-
|
171
|
-
|
172
|
-
if File.exist?(file.absolute_path)
|
173
|
-
@files.add(file)
|
174
|
-
else
|
175
|
-
say_debug "#{file} does not exist"
|
124
|
+
def files
|
125
|
+
@files ||= EMPTY_HASH.dup
|
176
126
|
end
|
177
|
-
end
|
178
127
|
|
179
|
-
|
180
|
-
|
181
|
-
return say_debug("Ignored {{warning:#{status.join(', ')}}} #{path}")
|
128
|
+
def paths
|
129
|
+
permitted.map(&:basename)
|
182
130
|
end
|
183
131
|
|
184
|
-
|
185
|
-
|
132
|
+
def include_file?(path)
|
133
|
+
permitted.include?(files.fetch(path, Undefined))
|
186
134
|
end
|
187
135
|
|
188
|
-
|
189
|
-
unless load_untracked?
|
190
|
-
return say_debug("Ignore #{path} as untracked files are ignored: #{status}")
|
191
|
-
end
|
136
|
+
private
|
192
137
|
|
193
|
-
|
138
|
+
def store(file)
|
139
|
+
files.store(file.key, file)
|
194
140
|
end
|
195
141
|
|
196
|
-
|
197
|
-
|
142
|
+
def get(path)
|
143
|
+
files.fetch(path)
|
198
144
|
end
|
199
145
|
|
200
|
-
|
146
|
+
def build(path, status)
|
147
|
+
store(Rfix::File.call(basename: path, status: status, repository: self))
|
148
|
+
rescue Dry::Struct::Error => e
|
149
|
+
raise Error, { path: path, status: status, message: e.message }.inspect
|
150
|
+
end
|
201
151
|
end
|
202
152
|
end
|