git-conform 1.0.0
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/.gitconform +9 -0
- data/.gitignore +21 -0
- data/.pryrc +10 -0
- data/.rubocop.yml +44 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +33 -0
- data/bin/console +9 -0
- data/bin/setup +13 -0
- data/exe/git-conform +112 -0
- data/git-conform.gemspec +32 -0
- data/lib/ext/inflections.rb +11 -0
- data/lib/ext/string.rb +14 -0
- data/lib/git/conform/checkers/base_checker.rb +31 -0
- data/lib/git/conform/checkers/carriage_return_character_checker.rb +11 -0
- data/lib/git/conform/checkers/false_checker.rb +11 -0
- data/lib/git/conform/checkers/file_checker.rb +50 -0
- data/lib/git/conform/checkers/file_not_empty_checker.rb +14 -0
- data/lib/git/conform/checkers/lowercase_filename_checker.rb +24 -0
- data/lib/git/conform/checkers/non_ascii_character_checker.rb +11 -0
- data/lib/git/conform/checkers/non_ascii_filename_checker.rb +11 -0
- data/lib/git/conform/checkers/noop_checker.rb +7 -0
- data/lib/git/conform/checkers/tab_character_checker.rb +18 -0
- data/lib/git/conform/checkers/trailing_whitespace_checker.rb +11 -0
- data/lib/git/conform/checkers/true_checker.rb +11 -0
- data/lib/git/conform/checkers/whitespace_filename_checker.rb +11 -0
- data/lib/git/conform/repo.rb +78 -0
- data/lib/git/conform/version.rb +6 -0
- data/lib/git/conform.rb +24 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b9f593b0c6ecde9c8f245306ff088350004f5aa6
|
4
|
+
data.tar.gz: 7a6893166c8e2080ba2a3d74ce18525d69c58370
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 515d9e675f88570a9be032c90989cfd80aae0f5d8e7066ce055cf5065ada096426ce484de4057cdc86e29a363f472da40c6cde43f684a3f8511a8df4753865c2
|
7
|
+
data.tar.gz: b7be897c09a27e24e565c168f56927bdd3e3fb19a2db2c03dc7b8958153c847867ad589580bd48cd679bc35ebd40c235ee8e98b80343f0217b668ab2ca22b208
|
data/.gitconform
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
[git "conform"]
|
2
|
+
checker = CarriageReturnCharacterChecker
|
3
|
+
checker = FileNotEmptyChecker
|
4
|
+
checker = LowercaseFilenameChecker
|
5
|
+
checker = NonAsciiCharacterChecker
|
6
|
+
checker = NonAsciiFilenameChecker
|
7
|
+
checker = TabCharacterChecker
|
8
|
+
checker = TrailingWhitespaceChecker
|
9
|
+
checker = WhitespaceFilenameChecker
|
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
vendor/bundle
|
13
|
+
pkg
|
14
|
+
rdoc
|
15
|
+
spec/reports
|
16
|
+
test/tmp
|
17
|
+
test/version_tmp
|
18
|
+
tmp
|
19
|
+
*.sublime-*
|
20
|
+
vcr_debug.log
|
21
|
+
rerun.txt
|
data/.pryrc
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# this loads all of "git-conform"
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'git/conform'
|
5
|
+
|
6
|
+
# utility function to set pry context
|
7
|
+
# to an instance of <Rugged::Repository>
|
8
|
+
def repository
|
9
|
+
pry Rugged::Repository.new(Dir.pwd)
|
10
|
+
end
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
Layout/AlignHash:
|
2
|
+
Enabled: false
|
3
|
+
Layout/EmptyLineAfterGuardClause:
|
4
|
+
Enabled: false
|
5
|
+
Layout/EmptyLinesAroundBlockBody:
|
6
|
+
Enabled: false
|
7
|
+
Layout/EmptyLinesAroundClassBody:
|
8
|
+
Enabled: false
|
9
|
+
Layout/EmptyLinesAroundModuleBody:
|
10
|
+
Enabled: false
|
11
|
+
Layout/EmptyLineBetweenDefs:
|
12
|
+
Enabled: false
|
13
|
+
Layout/MultilineOperationIndentation:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/AbcSize:
|
17
|
+
Enabled: false
|
18
|
+
Metrics/BlockLength:
|
19
|
+
Enabled: false
|
20
|
+
Metrics/ClassLength:
|
21
|
+
Enabled: false
|
22
|
+
Metrics/LineLength:
|
23
|
+
Enabled: false
|
24
|
+
Metrics/MethodLength:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Style/Alias:
|
28
|
+
Enabled: false
|
29
|
+
Style/BlockDelimiters:
|
30
|
+
Enabled: false
|
31
|
+
Style/Documentation:
|
32
|
+
Enabled: false
|
33
|
+
Style/EmptyCaseCondition:
|
34
|
+
Enabled: false
|
35
|
+
Style/FrozenStringLiteralComment:
|
36
|
+
Enabled: false
|
37
|
+
Style/SingleLineMethods:
|
38
|
+
Enabled: false
|
39
|
+
Style/TrailingCommaInArguments:
|
40
|
+
Enabled: false
|
41
|
+
Style/TrailingCommaInArrayLiteral:
|
42
|
+
Enabled: false
|
43
|
+
Style/TrailingCommaInHashLiteral:
|
44
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.8
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Peter Vandenberk
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Git::Conform
|
2
|
+
|
3
|
+
Conformity checking for git repositories
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'git-conform'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install git-conform
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# rubocop:disable Style/SymbolArray
|
2
|
+
# rubocop:disable Style/HashSyntax
|
3
|
+
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
|
6
|
+
task :validate_gemspec do
|
7
|
+
Bundler.load_gemspec('git-conform.gemspec').validate
|
8
|
+
end
|
9
|
+
|
10
|
+
task :version => :validate_gemspec do
|
11
|
+
puts Git::Conform::VERSION
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'rubocop/rake_task'
|
15
|
+
|
16
|
+
RuboCop::RakeTask.new(:rubocop)
|
17
|
+
|
18
|
+
require 'rake/testtask'
|
19
|
+
|
20
|
+
Rake::TestTask.new(:test) do |t|
|
21
|
+
t.libs << 'test'
|
22
|
+
t.libs << 'lib'
|
23
|
+
t.test_files = FileList['test/**/*_test.rb']
|
24
|
+
end
|
25
|
+
|
26
|
+
task :default => [:rubocop, :test]
|
27
|
+
|
28
|
+
task :documentation
|
29
|
+
|
30
|
+
Rake::Task['build'].enhance([:default, :documentation])
|
31
|
+
|
32
|
+
# rubocop:enable Style/HashSyntax
|
33
|
+
# rubocop:enable Style/SymbolArray
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/exe/git-conform
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'git/conform'
|
6
|
+
|
7
|
+
require 'slop'
|
8
|
+
|
9
|
+
options = Slop.parse(help: true) do |o|
|
10
|
+
|
11
|
+
o.banner = <<-"BANNER"
|
12
|
+
Usage: git-conform [options]
|
13
|
+
|
14
|
+
v#{Git::Conform::VERSION}
|
15
|
+
|
16
|
+
Options:
|
17
|
+
BANNER
|
18
|
+
|
19
|
+
o.on '--version', 'Print the version' do
|
20
|
+
dependencies = [
|
21
|
+
"rugged v#{Rugged::VERSION}",
|
22
|
+
"#{RUBY_ENGINE} #{RUBY_VERSION}p#{RUBY_PATCHLEVEL}",
|
23
|
+
].join(', ')
|
24
|
+
|
25
|
+
puts "#{Git::Conform::NAME} v#{Git::Conform::VERSION} (#{dependencies})"
|
26
|
+
exit(0)
|
27
|
+
end
|
28
|
+
|
29
|
+
o.on '--help', 'Print help message' do
|
30
|
+
puts o
|
31
|
+
exit(0)
|
32
|
+
end
|
33
|
+
|
34
|
+
o.on '--available', 'List all available conformity checkers'
|
35
|
+
o.on '--files', 'List all files in the git repo that will be processed'
|
36
|
+
o.on '--list', 'List all conformity checkers for this repo'
|
37
|
+
o.on '--verify', 'Verify that all conformity checkers exist'
|
38
|
+
o.on '--check', 'Run all conformity checkers'
|
39
|
+
o.on '--verbose', 'Make the conformity checkers verbose'
|
40
|
+
o.on '--gabby', 'Make the conformity checkers gabby'
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
if options[:available]
|
45
|
+
STDOUT.puts Git::Conform::FileChecker.available_checkers
|
46
|
+
exit(0)
|
47
|
+
end
|
48
|
+
|
49
|
+
repo = begin
|
50
|
+
Git::Conform::Repo.new(Git::Conform::Repo.discover(Dir.pwd).path)
|
51
|
+
rescue RuntimeError
|
52
|
+
unless $ERROR_INFO.message =~ /The given path is not a valid Git repository/
|
53
|
+
unless $ERROR_INFO.message =~ /Not a git repository \(or any of the parent directories\)/
|
54
|
+
raise # Rugged uses generic RuntimeErrors, so we have to check the exception messages...
|
55
|
+
end
|
56
|
+
end
|
57
|
+
nil
|
58
|
+
end
|
59
|
+
|
60
|
+
unless repo
|
61
|
+
STDERR.puts "fatal: Not a git repository (or any of the parent directories): #{Dir.pwd}"
|
62
|
+
exit(-1)
|
63
|
+
end
|
64
|
+
|
65
|
+
if options[:files]
|
66
|
+
unless (files = repo.files(type: :text)).empty?
|
67
|
+
STDOUT.puts files.sort.join("\n")
|
68
|
+
end
|
69
|
+
exit(0)
|
70
|
+
end
|
71
|
+
|
72
|
+
unless repo.git_conform_enabled?
|
73
|
+
STDERR.puts "fatal: unable to read config file '#{repo.git_conform_path}': No such file or directory"
|
74
|
+
exit(-1)
|
75
|
+
end
|
76
|
+
|
77
|
+
if options[:list]
|
78
|
+
unless (checkers = repo.conformity_checkers).empty?
|
79
|
+
STDOUT.puts checkers.sort.join("\n")
|
80
|
+
end
|
81
|
+
exit(0)
|
82
|
+
end
|
83
|
+
|
84
|
+
if options[:verify]
|
85
|
+
begin
|
86
|
+
repo.verify
|
87
|
+
rescue NameError
|
88
|
+
STDERR.puts "fatal: #{$ERROR_INFO.message}"
|
89
|
+
exit(-1)
|
90
|
+
end
|
91
|
+
exit(0)
|
92
|
+
end
|
93
|
+
|
94
|
+
if options[:check]
|
95
|
+
repo.conformity_checkers.each do |checker_class|
|
96
|
+
checker_class = constantize "Git::Conform::#{checker_class}"
|
97
|
+
puts checker_class.name.invert
|
98
|
+
repo.files(type: :text).each do |filename|
|
99
|
+
file_checker = checker_class.new(filename)
|
100
|
+
if file_checker.excluded?
|
101
|
+
puts 'EXCLUDE: ' + filename.blue if options[:verbose]
|
102
|
+
elsif file_checker.conforms?
|
103
|
+
puts 'INCLUDE: ' + filename.green if options[:gabby]
|
104
|
+
else
|
105
|
+
puts 'VIOLATE: ' + filename.red
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
exit(0)
|
110
|
+
end
|
111
|
+
|
112
|
+
# That's all, Folks!
|
data/git-conform.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'git/conform/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = Git::Conform::NAME
|
7
|
+
spec.version = Git::Conform::VERSION
|
8
|
+
spec.authors = ['Peter Vandenberk']
|
9
|
+
spec.email = ['pvandenberk@mac.com']
|
10
|
+
|
11
|
+
spec.description = 'Conformity checking for git repositories'
|
12
|
+
spec.summary = 'Conformity checking for git repositories'
|
13
|
+
spec.homepage = 'https://github.com/pvdb/git-conform'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = begin
|
17
|
+
`git ls-files -z`
|
18
|
+
.split("\x0")
|
19
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_dependency 'rugged', '~> 0.27'
|
26
|
+
spec.add_dependency 'slop', '~> 4.6'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler'
|
29
|
+
spec.add_development_dependency 'pry'
|
30
|
+
spec.add_development_dependency 'rake'
|
31
|
+
spec.add_development_dependency 'rubocop'
|
32
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-constantize
|
2
|
+
def constantize(camel_cased_word)
|
3
|
+
names = camel_cased_word.split('::')
|
4
|
+
names.shift if names.empty? || names.first.empty?
|
5
|
+
|
6
|
+
constant = Object
|
7
|
+
names.each do |name|
|
8
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
9
|
+
end
|
10
|
+
constant
|
11
|
+
end
|
data/lib/ext/string.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
def colorize(color_code) "\e[#{color_code}m#{self}\e[0m"; end
|
4
|
+
|
5
|
+
def bold() colorize('1'); end
|
6
|
+
def invert() colorize('7'); end
|
7
|
+
|
8
|
+
def red() colorize('31'); end
|
9
|
+
def blue() colorize('34'); end
|
10
|
+
def green() colorize('32'); end
|
11
|
+
|
12
|
+
def undent() gsub(/^.{#{slice(/^ +/).length}}/, ''); end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Git
|
2
|
+
module Conform
|
3
|
+
class BaseChecker
|
4
|
+
|
5
|
+
attr_reader :filename
|
6
|
+
|
7
|
+
def initialize(filename)
|
8
|
+
@filename = filename
|
9
|
+
raise "No such file - #{@filename}" unless File.exist? @filename
|
10
|
+
raise "Is a directory - #{@filename}" if File.directory? @filename
|
11
|
+
end
|
12
|
+
|
13
|
+
def excluded?
|
14
|
+
raise 'SubclassResponsibility'
|
15
|
+
end
|
16
|
+
|
17
|
+
def conforms?
|
18
|
+
raise 'SubclassResponsibility'
|
19
|
+
end
|
20
|
+
|
21
|
+
def check_exclusion
|
22
|
+
yield @filename if excluded?
|
23
|
+
end
|
24
|
+
|
25
|
+
def check_conformity
|
26
|
+
yield @filename unless excluded? || conforms?
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Git
|
2
|
+
module Conform
|
3
|
+
class FileChecker < BaseChecker
|
4
|
+
|
5
|
+
@file_exclusion_patterns = []
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
attr_reader :file_exclusion_patterns
|
10
|
+
|
11
|
+
def excluded?(filename)
|
12
|
+
file_exclusion_patterns.any? { |pattern|
|
13
|
+
File.fnmatch?(pattern, filename)
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def excluded?
|
20
|
+
self.class.excluded? @filename
|
21
|
+
end
|
22
|
+
|
23
|
+
def conforms?
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
def content
|
28
|
+
File.read(@filename)
|
29
|
+
end
|
30
|
+
|
31
|
+
@available_checkers = []
|
32
|
+
|
33
|
+
def self.inherited(subclass)
|
34
|
+
# keep track of all defined subclasses
|
35
|
+
# for the "--available" command option
|
36
|
+
@available_checkers << subclass
|
37
|
+
# ensure all file checkers "inherit" the @file_exclusion_patterns class instance variable
|
38
|
+
# http://stackoverflow.com/questions/10728735/inherit-class-level-instance-variables-in-ruby
|
39
|
+
subclass.instance_variable_set(:@file_exclusion_patterns, @file_exclusion_patterns.dup)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.available_checkers
|
43
|
+
@available_checkers.map(&:name).map { |class_name|
|
44
|
+
class_name.match(/\AGit::Conform::(.*Checker)\Z/)[1]
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Git
|
2
|
+
module Conform
|
3
|
+
class LowercaseFilenameChecker < FileChecker
|
4
|
+
|
5
|
+
@file_exclusion_patterns << '*Makefile*'
|
6
|
+
@file_exclusion_patterns << '*Brewfile*'
|
7
|
+
@file_exclusion_patterns << '*Rakefile*'
|
8
|
+
@file_exclusion_patterns << '*Gemfile*'
|
9
|
+
@file_exclusion_patterns << '*Guardfile*'
|
10
|
+
@file_exclusion_patterns << '*Capfile*'
|
11
|
+
@file_exclusion_patterns << '*Procfile*'
|
12
|
+
@file_exclusion_patterns << '*Vagrantfile*'
|
13
|
+
|
14
|
+
@file_exclusion_patterns << '*README*'
|
15
|
+
@file_exclusion_patterns << '*LICENSE*'
|
16
|
+
@file_exclusion_patterns << '*CODE_OF_CONDUCT*'
|
17
|
+
|
18
|
+
def conforms?
|
19
|
+
super && @filename.match(/[A-Z]/).nil?
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Git
|
2
|
+
module Conform
|
3
|
+
class TabCharacterChecker < FileChecker
|
4
|
+
|
5
|
+
@file_exclusion_patterns << '.gitconform'
|
6
|
+
# .gitconform is designed to be maintained using the 'git config'
|
7
|
+
# command, which uses tab characters for its indentation purposes
|
8
|
+
|
9
|
+
@file_exclusion_patterns << '.gitmodules'
|
10
|
+
# .gitmodules uses a format very similar to the 'git config' one!
|
11
|
+
|
12
|
+
def conforms?
|
13
|
+
super && !content.include?("\t")
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'rugged'
|
2
|
+
|
3
|
+
module Git
|
4
|
+
module Conform
|
5
|
+
class Repo < Rugged::Repository
|
6
|
+
|
7
|
+
def repo
|
8
|
+
# a bug/feature in Rugged prevents us from using instances of a subclass of Rugged::Repository
|
9
|
+
# in certain methods/places; instead it insists on an instance of Rugged::Repository itself...
|
10
|
+
# (meaning we can't use `self` on those occasions!) where is Barbara Liskov when you need her?
|
11
|
+
@repo ||= Rugged::Repository.new(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def git_conform_path
|
15
|
+
repo_path = File.join(workdir, '.gitconform')
|
16
|
+
File.exist?(repo_path) ? repo_path : Git::Conform::DEFAULT_PATH
|
17
|
+
end
|
18
|
+
|
19
|
+
def git_conform_enabled?
|
20
|
+
File.exist? git_conform_path
|
21
|
+
end
|
22
|
+
|
23
|
+
def conformity_checkers
|
24
|
+
@conformity_checkers ||= begin
|
25
|
+
# TODO: make this work via Rugged (why doesn't `Rugged::Config.new()` work?!?)
|
26
|
+
`git config -f #{git_conform_path} --get-all git.conform.checker`.chomp.split($RS)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def binary_patterns
|
31
|
+
@binary_patterns ||= begin
|
32
|
+
# TODO: make this work via Rugged (why doesn't `Rugged::Config.new()` work?!?)
|
33
|
+
`git config -f #{git_conform_path} --get-all git.conform.binary`.chomp.split($RS)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def exclusion_patterns
|
38
|
+
@exclusion_patterns ||= begin
|
39
|
+
# TODO: make this work via Rugged (why doesn't `Rugged::Config.new()` work?!?)
|
40
|
+
`git config -f #{git_conform_path} --get-all git.conform.exclusion`.chomp.split($RS)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def verify
|
45
|
+
conformity_checkers.each do |checker|
|
46
|
+
constantize "Git::Conform::#{checker}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def files(options = {})
|
51
|
+
type = options[:type] || :all
|
52
|
+
@files ||= {}
|
53
|
+
@files[type] ||= begin
|
54
|
+
files = []
|
55
|
+
repo.lookup(head.target.oid).tree.walk_blobs { |root, entry|
|
56
|
+
entry_path = (root.empty? ? entry[:name] : File.join(root, entry[:name]))
|
57
|
+
files << entry_path if binary?(entry) ? (type != :text) : (type != :binary)
|
58
|
+
}
|
59
|
+
files
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
# http://stackoverflow.com/questions/6119956/how-to-determine-if-git-handles-a-file-as-binary-or-as-text
|
66
|
+
# `pcregrep -l '\\x00' #{File.join(self.workdir, path)}` ; $? == 0
|
67
|
+
|
68
|
+
# TODO: is this the most performant way? (see also: "man 5 gitattributes" for inspiration)
|
69
|
+
|
70
|
+
def binary?(entry)
|
71
|
+
binary_patterns.any? { |glob_pattern|
|
72
|
+
File.fnmatch?(glob_pattern, entry[:name])
|
73
|
+
} || !@repo.lookup(entry[:oid]).read_raw.data.match(/\x00/).nil?
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/git/conform.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rugged'
|
2
|
+
require 'English'
|
3
|
+
|
4
|
+
require 'ext/string'
|
5
|
+
require 'ext/inflections'
|
6
|
+
|
7
|
+
module Git
|
8
|
+
module Conform
|
9
|
+
DEFAULT_PATH = File.expand_path('../../.gitconform', __dir__)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'git/conform/version'
|
14
|
+
require 'git/conform/repo'
|
15
|
+
|
16
|
+
# load the "base" conformity checkers first
|
17
|
+
require 'git/conform/checkers/base_checker.rb'
|
18
|
+
require 'git/conform/checkers/file_checker.rb'
|
19
|
+
|
20
|
+
# load all other checkers in 'lib/git/conform/checkers'
|
21
|
+
Dir.glob(
|
22
|
+
File.join(__dir__, 'conform', 'checkers', '*_checker.rb'),
|
23
|
+
&method(:require)
|
24
|
+
)
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-conform
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Vandenberk
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rugged
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.27'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.27'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: slop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Conformity checking for git repositories
|
98
|
+
email:
|
99
|
+
- pvandenberk@mac.com
|
100
|
+
executables:
|
101
|
+
- git-conform
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitconform"
|
106
|
+
- ".gitignore"
|
107
|
+
- ".pryrc"
|
108
|
+
- ".rubocop.yml"
|
109
|
+
- ".ruby-version"
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- exe/git-conform
|
117
|
+
- git-conform.gemspec
|
118
|
+
- lib/ext/inflections.rb
|
119
|
+
- lib/ext/string.rb
|
120
|
+
- lib/git/conform.rb
|
121
|
+
- lib/git/conform/checkers/base_checker.rb
|
122
|
+
- lib/git/conform/checkers/carriage_return_character_checker.rb
|
123
|
+
- lib/git/conform/checkers/false_checker.rb
|
124
|
+
- lib/git/conform/checkers/file_checker.rb
|
125
|
+
- lib/git/conform/checkers/file_not_empty_checker.rb
|
126
|
+
- lib/git/conform/checkers/lowercase_filename_checker.rb
|
127
|
+
- lib/git/conform/checkers/non_ascii_character_checker.rb
|
128
|
+
- lib/git/conform/checkers/non_ascii_filename_checker.rb
|
129
|
+
- lib/git/conform/checkers/noop_checker.rb
|
130
|
+
- lib/git/conform/checkers/tab_character_checker.rb
|
131
|
+
- lib/git/conform/checkers/trailing_whitespace_checker.rb
|
132
|
+
- lib/git/conform/checkers/true_checker.rb
|
133
|
+
- lib/git/conform/checkers/whitespace_filename_checker.rb
|
134
|
+
- lib/git/conform/repo.rb
|
135
|
+
- lib/git/conform/version.rb
|
136
|
+
homepage: https://github.com/pvdb/git-conform
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.5.2.3
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Conformity checking for git repositories
|
160
|
+
test_files: []
|