gitguard 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 926a4cd11bab7224ddd290066e613ff90f74bca0
4
+ data.tar.gz: c3abfebc9d0a410ea3a973441384cc7b9aba3418
5
+ SHA512:
6
+ metadata.gz: 319284829202d4a4dfbad0ac2ea97156ffd835ae6381de39f978304074cae7f59f9ebd534a6230f5693ac5eacfada277ac9d79e8b85a67e24fe4413bab8d1450
7
+ data.tar.gz: 44ba7bc832a2418ad4f02185ec78aec4480733146f83a0cd2862db76a4cb18c7e91af389e0c7676ff712352638a0583032681451fea955fd0b9160e2d6a5605c
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at akm2000@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gitguard.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 akm
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,81 @@
1
+ # gitguard
2
+
3
+ `gitguard` supports to avoid mixing human code and generated code in a git commit.
4
+
5
+ If there is/are change(s) to be commit, `gitguard` quits the command
6
+ before you run command which generates something like this:
7
+
8
+ ```bash
9
+ $ bin/rails g migtation create_books title:string
10
+ [gitguard] There are files that need to be committed first.
11
+ [gitguard] git status
12
+ On branch features/gitguard
13
+ Changes not staged for commit:
14
+ (use "git add <file>..." to update what will be committed)
15
+ (use "git checkout -- <file>..." to discard changes in working directory)
16
+
17
+ modified: Gemfile
18
+ modified: Gemfile.lock
19
+
20
+ no changes added to commit (use "git add" and/or "git commit -a")
21
+ ```
22
+
23
+ If there is no change to be commit, `gitguard` automatically commits
24
+ the changes which is made by the command.
25
+
26
+ `gitguard` supports not only `bin/rails generate` but `rake` tasks.
27
+ You can configure rake task names in `.gitguard` file.
28
+
29
+
30
+ ## Installation
31
+
32
+ Add this line to your application's Gemfile:
33
+
34
+ ```ruby
35
+ gem 'gitguard', group: :development
36
+ ```
37
+
38
+ And then execute:
39
+
40
+ $ bundle
41
+
42
+ Or install it yourself as:
43
+
44
+ $ gem install gitguard
45
+
46
+ ## Setup
47
+
48
+ ```bash
49
+ $ bin/rails generate gitguard:install
50
+ ```
51
+
52
+ A file `.gitguard` will be generated. You can configure the behavior by editing the file.
53
+
54
+ ## Usage
55
+
56
+ Nothing special to do after setup. You can use `rails generate` and `rake` like before.
57
+
58
+ ### Disabling
59
+
60
+ If you don't want to commit the changes, you can disable gitguard by environment variable `GITGUARD` like this:
61
+
62
+ ```bash
63
+ $ bin/rails db:migrate GITGUARD=off
64
+ ```
65
+
66
+
67
+ ## Development
68
+
69
+ 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.
70
+
71
+ 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).
72
+
73
+ ## Contributing
74
+
75
+ Bug reports and pull requests are welcome on GitHub at https://github.com/akm/gitguard. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
76
+
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
81
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gitguard"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "gitguard"
data/gitguard.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gitguard/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gitguard"
8
+ spec.version = Gitguard::VERSION
9
+ spec.authors = ["akm"]
10
+ spec.email = ["akm2000@gmail.com"]
11
+
12
+ spec.summary = %q{Keep commit clear by checking workspace before generate something}
13
+ spec.description = %q{Keep commit clear by checking workspace before generate something}
14
+ spec.homepage = "https://github.com/akm/gitguard"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Gitguard
4
+ class InstallGenerator < ::Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ desc "Generate config file for gitguard"
8
+
9
+ def generate_config
10
+ template 'config.yml', '.gitguard'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ tasks:
2
+ - dump
3
+ - generate
4
+ - migrate
@@ -0,0 +1,36 @@
1
+ require 'gitguard'
2
+
3
+ require 'yaml'
4
+
5
+ module Gitguard
6
+ module Config
7
+ extend self
8
+
9
+ CONFIG_FILENAME = '.gitguard'.freeze
10
+
11
+ def config
12
+ @config ||= load_config
13
+ end
14
+
15
+ def load_config
16
+ YAML.load_file(config_path)
17
+ end
18
+
19
+ def config_path
20
+ unless @config_path
21
+ dir = DirSearch.up{|dir| File.readable?(File.join(dir, CONFIG_FILENAME)) }
22
+ raise Error, "File not found: #{CONFIG_FILENAME}" unless dir
23
+ @config_path = File.join(dir, CONFIG_FILENAME)
24
+ end
25
+ @config_path
26
+ end
27
+
28
+ def rake_task_patterns
29
+ config['tasks'].map{|t| Regexp.new(t) }
30
+ end
31
+
32
+ def target_rake_task?(task)
33
+ rake_task_patterns.any?{|ptn| ptn =~ task}
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ require 'gitguard'
2
+
3
+ module Gitguard
4
+ module DirSearch
5
+ module_function
6
+
7
+ class DirNotFound < StandardError
8
+ end
9
+
10
+ def up(dir = Dir.pwd, &block)
11
+ return dir if yield(dir)
12
+ parent = File.dirname(dir)
13
+ if dir == parent
14
+ return nil
15
+ else
16
+ return up(parent, &block)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ module Gitguard
2
+ module Rails
3
+ module CommandsTasks
4
+
5
+ TARGET_COMMANDS = %(plugin generate destroy).freeze
6
+
7
+ def require_command!(command)
8
+ if target?(command.to_s)
9
+ Gitguard.run("bin/rails #{command} #{argv.join(' ')}"){ super }
10
+ else
11
+ super
12
+ end
13
+ end
14
+
15
+ def target?(command)
16
+ return false if argv.empty?
17
+ Gitguard.enabled? && TARGET_COMMANDS.include?(command) &&
18
+ (command == 'generate' ? !argv.include?('gitguard:install') : true)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ require "gitguard"
2
+
3
+ module Gitguard
4
+ module Rails
5
+ autoload :CommandsTasks, 'gitguard/rails/commands_tasks'
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ require 'gitguard'
2
+
3
+ require 'rails'
4
+ require 'rails/commands/commands_tasks'
5
+
6
+ module Gitguard
7
+ class Railtie < ::Rails::Railtie
8
+ generators do
9
+ ::Rails::CommandsTasks.__send__(:prepend, ::Gitguard::Rails::CommandsTasks)
10
+ end
11
+
12
+ rake_tasks do
13
+ ::Rake::Application.__send__(:prepend, ::Gitguard::RakeApplication)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ require 'gitguard'
2
+
3
+ require 'rake/application'
4
+
5
+ module Gitguard
6
+ module RakeApplication
7
+ def top_level
8
+ if Gitguard.enabled? && top_level_tasks.any?{|arg| Gitguard.target_rake_task?(arg)}
9
+ Gitguard.run("bin/rake #{top_level_tasks.join(' ')}"){ super }
10
+ else
11
+ super
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,42 @@
1
+ require 'gitguard'
2
+ require 'shellwords'
3
+
4
+ require 'yaml'
5
+
6
+ module Gitguard
7
+ class Runner
8
+ attr_reader :user_command
9
+ def initialize(user_command)
10
+ @user_command = user_command
11
+ end
12
+
13
+ def execute(&block)
14
+ unless clean?
15
+ $stderr.puts "\e[31m[gitguard] There are files that need to be committed first.\e[0m"
16
+ $stderr.puts "[gitguard] git status"
17
+ system 'git status'
18
+ exit(1)
19
+ end
20
+ yield
21
+ return if clean?
22
+ root_dir = DirSearch.up{|dir| Dir.exist?(File.join(dir, '.git')) }
23
+ raise Error, "Directory not found: .git" unless root_dir
24
+ Dir.chdir(root_dir) do
25
+ cmd = "git add . && git commit -m #{Shellwords.escape(user_command)}"
26
+ puts "\e[34m#{cmd}"
27
+ r = false
28
+ begin
29
+ r = system(cmd)
30
+ ensure
31
+ print "\e[0m"
32
+ end
33
+ raise Error, "Error on #{cmd}" unless r
34
+ end
35
+ end
36
+
37
+ def clean?
38
+ system("git diff --exit-code > /dev/null")
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module Gitguard
2
+ VERSION = "0.1.0"
3
+ end
data/lib/gitguard.rb ADDED
@@ -0,0 +1,31 @@
1
+ require "gitguard/version"
2
+ require 'gitguard/railtie'
3
+
4
+ module Gitguard
5
+ autoload :Config , 'gitguard/config'
6
+ autoload :DirSearch, 'gitguard/dir_search'
7
+ autoload :Rails , 'gitguard/rails'
8
+ autoload :RakeApplication, 'gitguard/rake_application'
9
+ autoload :Runner , 'gitguard/runner'
10
+
11
+ class Error < StandardError
12
+ end
13
+
14
+ class << self
15
+ def run(user_command, &block)
16
+ Runner.new(user_command).execute(&block)
17
+ end
18
+
19
+ def target_rake_task?(task)
20
+ Config.target_rake_task?(task)
21
+ end
22
+
23
+ def enabled?
24
+ !disabled?
25
+ end
26
+
27
+ def disabled?
28
+ ENV['GITGUARD'] =~ /false|no|off|0/i
29
+ end
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitguard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - akm
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Keep commit clear by checking workspace before generate something
56
+ email:
57
+ - akm2000@gmail.com
58
+ executables:
59
+ - gitguard-rails
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - exe/gitguard-rails
74
+ - gitguard.gemspec
75
+ - lib/generators/gitguard/install_generator.rb
76
+ - lib/generators/gitguard/templates/config.yml
77
+ - lib/gitguard.rb
78
+ - lib/gitguard/config.rb
79
+ - lib/gitguard/dir_search.rb
80
+ - lib/gitguard/rails.rb
81
+ - lib/gitguard/rails/commands_tasks.rb
82
+ - lib/gitguard/railtie.rb
83
+ - lib/gitguard/rake_application.rb
84
+ - lib/gitguard/runner.rb
85
+ - lib/gitguard/version.rb
86
+ homepage: https://github.com/akm/gitguard
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.6.4
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Keep commit clear by checking workspace before generate something
110
+ test_files: []