git-rails-changes 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +36 -0
- data/LICENSE.txt +21 -0
- data/README.md +60 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/git-rails-changes +7 -0
- data/git-rails-changes.gemspec +29 -0
- data/lib/git/rails/changes/version.rb +10 -0
- data/lib/git/rails/changes.rb +112 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1a4a54351fe041ca0f0c821dd0a2b823d61905bead6bf0e70ec700bd95e3d86d
|
4
|
+
data.tar.gz: d72ddbb4fb378847a0a61ecb45495fb6446d7e3be210e20556b94ec54e62cf85
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4b731fbf1e090556d6499a0f80f6a10d4206dcfd9cec16f88310e78f5614e333af0c373e198c7b2f4362aaa4385e4d49f7caaf3017357023325137b69cfa75b4
|
7
|
+
data.tar.gz: e4ebece6823a7be9d4cec5ee3dcbfb998a510046f9fc3bc128b6f1ab75dc742c1fe1169571a52c439961a72bcb15c8a22bf2aa1ca4945b4d79146d7ae1dfe5e5
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.5
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
git-rails-changes (0.1.1)
|
5
|
+
optimist (~> 3.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.5.0)
|
11
|
+
optimist (3.0.1)
|
12
|
+
rake (13.0.6)
|
13
|
+
rspec (3.11.0)
|
14
|
+
rspec-core (~> 3.11.0)
|
15
|
+
rspec-expectations (~> 3.11.0)
|
16
|
+
rspec-mocks (~> 3.11.0)
|
17
|
+
rspec-core (3.11.0)
|
18
|
+
rspec-support (~> 3.11.0)
|
19
|
+
rspec-expectations (3.11.0)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.11.0)
|
22
|
+
rspec-mocks (3.11.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.11.0)
|
25
|
+
rspec-support (3.11.0)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
git-rails-changes!
|
32
|
+
rake (~> 13.0)
|
33
|
+
rspec (~> 3.0)
|
34
|
+
|
35
|
+
BUNDLED WITH
|
36
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Bart Agapinan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Git::Rails::Changes
|
2
|
+
|
3
|
+
`git-rails-changes` is a command line tool for extracting some useful rails-related files from your git working directory.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'git-rails-changes', require: false
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install git-rails-changes
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Find a full list of command line options by running `git-rails --help`
|
24
|
+
|
25
|
+
Some useful commands:
|
26
|
+
```
|
27
|
+
git-rails-changes --cached
|
28
|
+
```
|
29
|
+
will output a list of files that are staged in the git working directory.
|
30
|
+
|
31
|
+
```
|
32
|
+
git-rails-changes --unstaged-only
|
33
|
+
```
|
34
|
+
will output a list of files that are changed but not staged in the current git working directory.
|
35
|
+
|
36
|
+
You can combine options to run a command on the output files:
|
37
|
+
```
|
38
|
+
git-rails-changes --unstaged-only --run-rspec
|
39
|
+
```
|
40
|
+
will run the list of unstaged files through rspec (matching `.rb` files to `_spec.rb` files)
|
41
|
+
|
42
|
+
```
|
43
|
+
git-rails-changes --cached --run-rubocop-autocorrect
|
44
|
+
```
|
45
|
+
will run staged files through rubocop with the `--safe-auto-correct` option.
|
46
|
+
|
47
|
+
## Development
|
48
|
+
|
49
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
50
|
+
|
51
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/viamin/git-rails-changes.
|
56
|
+
|
57
|
+
|
58
|
+
## License
|
59
|
+
|
60
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "git/rails/changes"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/git/rails/changes/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "git-rails-changes"
|
7
|
+
spec.version = Git::Rails::Changes::VERSION
|
8
|
+
spec.authors = ["Bart Agapinan"]
|
9
|
+
spec.email = ["bart@sonic.net"]
|
10
|
+
|
11
|
+
spec.summary = "Find recently changed files in your git working directory and some matching counterparts"
|
12
|
+
spec.description = "git-rails-changes will find files that have changed between branches, that are staged, or modified but not staged. It can find matching rspec tests for rails files"
|
13
|
+
spec.homepage = "https://github.com/viamin/git-rails-changes"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
18
|
+
|
19
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
21
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
22
|
+
end
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_runtime_dependency "optimist", "~> 3.0"
|
29
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "git/rails/changes/version"
|
4
|
+
require "optimist"
|
5
|
+
|
6
|
+
module Git
|
7
|
+
module Rails
|
8
|
+
module Changes
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def main
|
13
|
+
opts = Optimist.options do
|
14
|
+
opt "all-files", "Don't exclude any files"
|
15
|
+
opt "include-deleted", "Don't filter out deleted files"
|
16
|
+
opt "code-only", "Filter out .yml, .json, and .md files"
|
17
|
+
opt "spec-only", "Convert all paths to spec and remove non-spec files"
|
18
|
+
opt "cached", "Only compare staged files (useful for pre-commit hooks)"
|
19
|
+
opt "unstaged-only", "Only compare unstaged/uncommitted files"
|
20
|
+
opt "branch",
|
21
|
+
"Compare all changes with given branch (default main)",
|
22
|
+
type: :string,
|
23
|
+
default: "main"
|
24
|
+
opt "replace-blank",
|
25
|
+
"Prevent blank output by sending alternate output",
|
26
|
+
type: :string,
|
27
|
+
default: "--version"
|
28
|
+
opt "rspec-pre-commit", "Preset option for getting cached specs safely"
|
29
|
+
opt "run-rspec", "Run rspec on the files found by the given options"
|
30
|
+
opt "run-rspec-fail-fast", "Run rspec with the --fail-fast option"
|
31
|
+
opt "run-rubocop", "Run rubocop on the files found by the given options"
|
32
|
+
opt "run-rubocop-autocorrect", "Run rubocop with the --safe-auto-correct flag"
|
33
|
+
opt "debug", "Print all command line options"
|
34
|
+
end
|
35
|
+
|
36
|
+
if opts["rspec-pre-commit"]
|
37
|
+
opts["cached"] = true
|
38
|
+
opts["spec-only"] = true
|
39
|
+
opts["replace-blank"] = "--version"
|
40
|
+
end
|
41
|
+
|
42
|
+
puts opts if opts["debug"]
|
43
|
+
|
44
|
+
raise "Can't use both 'cached' (-c) and 'unstaged-only' (-u) flags" if opts["cached"] && opts["unstaged-only"]
|
45
|
+
|
46
|
+
# gather all changes
|
47
|
+
file_list = if opts["unstaged-only"]
|
48
|
+
`git ls-files --modified --others #{"--exclude-standard" unless opts["all-files"]}`
|
49
|
+
elsif opts["cached"]
|
50
|
+
`git diff --name-status --cached #{"| grep -v '\''^D'\''" unless opts["include-deleted"]} | awk '{print $2}'`
|
51
|
+
else
|
52
|
+
`git diff --name-status #{opts["branch"]} #{"| grep -v '\''^D'\''" unless opts["include-deleted"]} | awk '{print $2}'`
|
53
|
+
end
|
54
|
+
file_list = file_list.split("\n")
|
55
|
+
|
56
|
+
if opts["spec-only"]
|
57
|
+
spec_array = file_list.map { |file| spec?(file) ? file : spec_from_code(file) }
|
58
|
+
spec_array = spec_array.select { |file| file.match?(/_spec.rb$/) }
|
59
|
+
spec_array = spec_array.map { |spec| File.exist?(File.expand_path(spec, `pwd`.strip)) ? spec : nil }
|
60
|
+
file_list = spec_array.compact.uniq
|
61
|
+
end
|
62
|
+
|
63
|
+
file_list = file_list.reject { |file| /\.(yml|json|md)\Z/.match(file) } if opts["code-only"]
|
64
|
+
|
65
|
+
command = []
|
66
|
+
if opts["run-rspec"] || opts["run-rspec-fail-fast"]
|
67
|
+
command << `which spring`.strip
|
68
|
+
command << "rspec"
|
69
|
+
command << "--fail-fast" if opts["run-rspec-fail-fast"]
|
70
|
+
elsif opts["run-rubocop"] || opts["run-rubocop-autocorrect"]
|
71
|
+
command << `which rubocop`.strip
|
72
|
+
command << "--safe-auto-correct" if opts["run-rubocop-autocorrect"]
|
73
|
+
else
|
74
|
+
command << `which echo`.strip
|
75
|
+
file_list = [file_list.join("\n")]
|
76
|
+
end
|
77
|
+
|
78
|
+
if file_list.empty? && opts["replace-blank"]
|
79
|
+
command << opts["replace-blank"]
|
80
|
+
else
|
81
|
+
command.concat(file_list)
|
82
|
+
end
|
83
|
+
|
84
|
+
command.compact!
|
85
|
+
|
86
|
+
exec(*command)
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def spec?(file_name)
|
92
|
+
file_name.match?(/_spec.rb$/)
|
93
|
+
end
|
94
|
+
|
95
|
+
def spec_from_code(file_name)
|
96
|
+
if /erb$|haml$|slim$/.match?(file_name)
|
97
|
+
return file_name
|
98
|
+
.gsub("app/", "spec/")
|
99
|
+
.gsub(".haml", ".haml_spec.rb")
|
100
|
+
.gsub(".erb", ".erb_spec.rb")
|
101
|
+
.gsub(".slim", ".slim_spec.rb")
|
102
|
+
end
|
103
|
+
file_name = file_name.gsub(".rb", "_spec.rb")
|
104
|
+
|
105
|
+
return file_name.gsub("lib/", "spec/lib/") if file_name.match?(%r{^/?lib/})
|
106
|
+
|
107
|
+
file_name.gsub("app/", "spec/")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-rails-changes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bart Agapinan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-04-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: optimist
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
description: git-rails-changes will find files that have changed between branches,
|
28
|
+
that are staged, or modified but not staged. It can find matching rspec tests for
|
29
|
+
rails files
|
30
|
+
email:
|
31
|
+
- bart@sonic.net
|
32
|
+
executables:
|
33
|
+
- git-rails-changes
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- ".rspec"
|
38
|
+
- ".ruby-version"
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bin/console
|
45
|
+
- bin/setup
|
46
|
+
- exe/git-rails-changes
|
47
|
+
- git-rails-changes.gemspec
|
48
|
+
- lib/git/rails/changes.rb
|
49
|
+
- lib/git/rails/changes/version.rb
|
50
|
+
homepage: https://github.com/viamin/git-rails-changes
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata:
|
54
|
+
homepage_uri: https://github.com/viamin/git-rails-changes
|
55
|
+
source_code_uri: https://github.com/viamin/git-rails-changes
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 2.6.0
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubygems_version: 3.3.10
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Find recently changed files in your git working directory and some matching
|
75
|
+
counterparts
|
76
|
+
test_files: []
|