pre-commit 0.1.19 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/pre-commit +6 -25
- data/lib/pre-commit/checks.rb +8 -0
- data/lib/pre-commit/cli.rb +42 -0
- data/templates/pre-commit-hook +11 -0
- metadata +5 -3
data/bin/pre-commit
CHANGED
@@ -1,18 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
#!/usr/bin/env ruby
|
5
|
-
|
6
|
-
require 'rubygems'
|
7
|
-
require 'pre-commit'
|
8
|
-
|
9
|
-
exit_status = PreCommit.checks_to_run.inject(true) do |acc, cmd|
|
10
|
-
acc = cmd.call && acc
|
11
|
-
end
|
12
|
-
|
13
|
-
exit(exit_status ? 0 : 1)
|
3
|
+
require 'pre-commit/cli'
|
14
4
|
|
15
|
-
|
5
|
+
PRE_COMMIT_HOOK_PATH = '.git/hooks/pre-commit'
|
16
6
|
|
17
7
|
if ARGV[0] != "install"
|
18
8
|
puts "Usage: pre-commit install"
|
@@ -24,17 +14,8 @@ if !File.exists?(".git")
|
|
24
14
|
exit(1)
|
25
15
|
end
|
26
16
|
|
27
|
-
|
28
|
-
|
29
|
-
exit(1)
|
30
|
-
end
|
31
|
-
|
32
|
-
File.open(".git/hooks/pre-commit","w") {|f|
|
33
|
-
f.write(template)
|
34
|
-
}
|
35
|
-
|
36
|
-
require 'fileutils'
|
37
|
-
|
38
|
-
FileUtils.chmod(0755, ".git/hooks/pre-commit")
|
17
|
+
cli = PreCommit::Cli.new
|
18
|
+
cli.install
|
39
19
|
|
40
|
-
puts "Installed hook:
|
20
|
+
puts "Installed hook: #{PRE_COMMIT_HOOK_PATH}"
|
21
|
+
puts
|
data/lib/pre-commit/checks.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'pre-commit/base'
|
3
|
+
|
4
|
+
class PreCommit
|
5
|
+
class Cli
|
6
|
+
|
7
|
+
PRE_COMMIT_HOOK_PATH = '.git/hooks/pre-commit'
|
8
|
+
|
9
|
+
def answered_yes?(answer)
|
10
|
+
answer =~ /y\n/i || answer == "\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
def install
|
14
|
+
if File.exists?(PRE_COMMIT_HOOK_PATH)
|
15
|
+
ask_to_overwrite
|
16
|
+
end
|
17
|
+
|
18
|
+
install_pre_commit_hook
|
19
|
+
end
|
20
|
+
|
21
|
+
def ask_to_overwrite
|
22
|
+
puts "pre-commit: WARNING There is already a pre-commit hook installed in this git repo."
|
23
|
+
print "Would you like to overwrite it? [Yn] "
|
24
|
+
answer = $stdin.gets
|
25
|
+
|
26
|
+
if answered_yes?(answer)
|
27
|
+
FileUtils.rm(PRE_COMMIT_HOOK_PATH)
|
28
|
+
else
|
29
|
+
puts "Not overwriting existing hook: #{PRE_COMMIT_HOOK_PATH}"
|
30
|
+
puts
|
31
|
+
exit(1)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def install_pre_commit_hook
|
36
|
+
hook = File.join(PreCommit.root, 'templates', 'pre-commit-hook')
|
37
|
+
FileUtils.cp(hook, PRE_COMMIT_HOOK_PATH)
|
38
|
+
FileUtils.chmod(0755, PRE_COMMIT_HOOK_PATH)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pre-commit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: execjs
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- lib/pre-commit/checks/php_check.rb
|
49
49
|
- lib/pre-commit/checks/tabs.rb
|
50
50
|
- lib/pre-commit/checks.rb
|
51
|
+
- lib/pre-commit/cli.rb
|
51
52
|
- lib/pre-commit/runner.rb
|
52
53
|
- lib/pre-commit/utils.rb
|
53
54
|
- lib/pre-commit.rb
|
@@ -58,6 +59,7 @@ files:
|
|
58
59
|
- lib/support/jslint/lint.js
|
59
60
|
- lib/support/whitespace/whitespace
|
60
61
|
- lib/support/whitespace/whitespace_checker.rb
|
62
|
+
- templates/pre-commit-hook
|
61
63
|
- README.md
|
62
64
|
- !binary |-
|
63
65
|
YmluL3ByZS1jb21taXQ=
|
@@ -83,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
85
|
version: '0'
|
84
86
|
requirements: []
|
85
87
|
rubyforge_project:
|
86
|
-
rubygems_version: 1.8.
|
88
|
+
rubygems_version: 1.8.24
|
87
89
|
signing_key:
|
88
90
|
specification_version: 3
|
89
91
|
summary: A slightly better git pre-commit hook
|