fit-commit 3.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ad77d4fef04820ea606a791e318dfd42b296b76
4
- data.tar.gz: 636584b83de8821f587846dd5be38acc2867fdc4
3
+ metadata.gz: 8699deb0617713906feec2843b053835d4eff93a
4
+ data.tar.gz: f7131e71ae0921ce4aaf1f6873331b008d769d1f
5
5
  SHA512:
6
- metadata.gz: d1a1af025a01e22528921a00201e9e6706d8d3c09eec51e51d6b5e55400cb92cbed7e3b87082c069bea2ffc9ce470bf10548e3ed095fd9b96e766d159834f13a
7
- data.tar.gz: 2decbff9cb0fb3aa3e88170a962776d9384ed0b54efbfa30fb4db314eb0a739c9cc5baf422133f9d92e786bce9f7bd5a45ac95b658710eeba675452453ad1ae1
6
+ metadata.gz: f4878977c4b1aa0aadc837053ffb3afddb63c9aeb46d6bd6bf24f78c86dab3da74cf61c41ca4e3cb3de78b8bd3d2737e19cec5e75406e5edf9c234eb2ee36c40
7
+ data.tar.gz: cac7ba464d93602fb88462dc96de993feb35ca9c5b6b0d10c69f7e4fbede134d2d35b50c81987155125d4bd1a29513687351338080d83e6a87bb258f67791cbf
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ### v3.1.0 (2015-09-27)
4
+ - Allow execution from scripts and GUI clients
5
+
3
6
  ### v3.0.1 (2015-09-21)
4
7
  - Allow granular configuration overrides
5
8
 
data/fit-commit.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
9
9
  gem.email = ["foley3@gmail.com"]
10
10
  gem.homepage = "https://github.com/m1foley/fit-commit"
11
11
  gem.summary = "A Git hook to validate your commit messages"
12
- gem.description = "A Git hook to validate your commit messages, based largely on Tim Pope's authoritative guide."
12
+ gem.description = "A Git hook to validate your commit messages based on community standards."
13
13
  gem.files = `git ls-files`.split("\n")
14
14
  gem.executables = ["fit-commit"]
15
15
  gem.default_executable = "fit-commit"
@@ -22,22 +22,30 @@ module FitCommit
22
22
  run_validators
23
23
  return EXIT_CODE_ALLOW_COMMIT if [errors, warnings].all?(&:empty?)
24
24
  print_results
25
+ allow_commit = errors.empty? || ask_force_commit
25
26
 
26
- allow_commit = errors.empty?
27
- unless allow_commit
28
- stderr.print "\nForce commit? [y/n] "
29
- return EXIT_CODE_REJECT_COMMIT unless stdin.gets =~ /y/i
30
- allow_commit = true
27
+ if allow_commit
28
+ stderr.print "\n"
29
+ EXIT_CODE_ALLOW_COMMIT
30
+ else
31
+ EXIT_CODE_REJECT_COMMIT
31
32
  end
32
-
33
- stderr.print "\n"
34
- allow_commit ? EXIT_CODE_ALLOW_COMMIT : EXIT_CODE_REJECT_COMMIT
35
33
  rescue Interrupt # Ctrl-c
36
34
  EXIT_CODE_REJECT_COMMIT
37
35
  end
38
36
 
39
37
  private
40
38
 
39
+ def ask_force_commit
40
+ return unless interactive?
41
+ stderr.print "\nForce commit? [y/n] "
42
+ stdin.gets =~ /y/i
43
+ end
44
+
45
+ def interactive?
46
+ stdin.tty?
47
+ end
48
+
41
49
  def run_validators
42
50
  validators.each do |validator|
43
51
  validator.validate(lines)
@@ -1,3 +1,3 @@
1
1
  module FitCommit
2
- VERSION = "3.0.1"
2
+ VERSION = "3.1.0"
3
3
  end
@@ -1,13 +1,4 @@
1
1
  #!/usr/bin/env sh
2
- #
3
- # This hook will attempt to setup your environment before running checks.
4
-
5
- if which rvm > /dev/null 2>&1
6
- then cmd="rvm default do ruby"
7
- elif which rbenv > /dev/null 2>&1
8
- then cmd="rbenv exec ruby"
9
- else cmd="ruby"
10
- fi
11
2
 
12
3
  export COMMIT_MESSAGE_PATH=$1
13
4
  if [ -z "$COMMIT_MESSAGE_PATH" ]; then
@@ -35,7 +26,19 @@ if [ -z "$GIT_BRANCH_NAME" ]; then
35
26
  exit 0
36
27
  fi
37
28
 
38
- ${cmd} -rrubygems -e '
29
+ if which rvm > /dev/null 2>&1
30
+ then cmd="rvm default do ruby"
31
+ elif which rbenv > /dev/null 2>&1
32
+ then cmd="rbenv exec ruby"
33
+ else cmd="ruby"
34
+ fi
35
+
36
+ # allow user input if running in a terminal
37
+ if [ -t 1 ]; then
38
+ exec < /dev/tty
39
+ fi
40
+
41
+ $cmd -rrubygems -e '
39
42
  begin
40
43
  require "fit_commit"
41
44
  true
@@ -46,4 +49,4 @@ fit-commit: Did you set your Ruby version?
46
49
  MESSAGE
47
50
  false
48
51
  end and FitCommit.run
49
- ' < /dev/tty
52
+ '
@@ -5,18 +5,57 @@ require "expect"
5
5
  describe "Install and run in a fresh Git repo" do
6
6
  BINARY_PATH = File.expand_path("../../../bin/fit-commit", __FILE__)
7
7
 
8
- it "installs with no errors" do
8
+ def shell_commands(gitdir)
9
+ "cd #{gitdir} && git init && #{BINARY_PATH} install && git commit --allow-empty -m '#{commit_message}'"
10
+ end
11
+
12
+ let(:results) do
13
+ output = ""
9
14
  Dir.mktmpdir do |gitdir|
10
- results = ""
11
- commands = "cd #{gitdir} && git init && #{BINARY_PATH} install && git commit --allow-empty -m fixing"
12
- PTY.spawn(commands) do |pty_out, _pty_in, _pty_pid|
13
- pty_out.expect(/Force commit\?/, 3) do |expect_out|
14
- results << Array(expect_out).join
15
- "n"
15
+ PTY.spawn(shell_commands(gitdir)) do |pty_out, _pty_in, _pty_pid|
16
+ if user_input
17
+ pty_out.expect(/Force commit\?/, 3) do |expect_out|
18
+ output << Array(expect_out).join
19
+ user_input
20
+ end
21
+ else
22
+ output << pty_out.read
16
23
  end
17
24
  end
18
- assert_match(/^fixing/, results)
19
- assert_match(/^1: Error: Message must use imperative present tense/, results)
25
+ end
26
+ output
27
+ end
28
+
29
+ describe "invalid commit message" do
30
+ let(:commit_message) { "fixing foo" }
31
+ let(:user_input) { "n" }
32
+ it "disallows commit" do
33
+ assert_match(/^#{commit_message}/, results)
34
+ assert_match(/^1: Error: /, results)
35
+ refute_match(/Warning:/, results)
36
+ refute_match(/^\[master .+\]/, results)
37
+ end
38
+ end
39
+
40
+ describe "valid commit message" do
41
+ let(:commit_message) { "Fix foo" }
42
+ let(:user_input) { nil }
43
+ it "allows commit" do
44
+ refute_match(/^#{commit_message}/, results)
45
+ refute_match(/Error:/, results)
46
+ refute_match(/Warning:/, results)
47
+ assert_match(/^\[master .+\] #{commit_message}/, results)
48
+ end
49
+ end
50
+
51
+ describe "commit message with warning only" do
52
+ let(:commit_message) { "X" * 51 }
53
+ let(:user_input) { nil }
54
+ it "allows commit" do
55
+ refute_match(/^#{commit_message}/, results)
56
+ refute_match(/Error/, results)
57
+ assert_match(/^1: Warning: /, results)
58
+ assert_match(/^\[master .+\] #{commit_message}/, results)
20
59
  end
21
60
  end
22
61
  end
@@ -65,31 +65,49 @@ describe FitCommit::Runner do
65
65
  describe "commit msg contains errors" do
66
66
  let(:commit_msg) { "foo.\nbar" }
67
67
 
68
- def assert_error_output
68
+ def assert_error_output(interactive: true)
69
69
  stderr_lines = stderr.read.lines.map(&:chomp)
70
- assert_equal 8, stderr_lines.size
70
+ expected_lines = interactive ? 8 : 6
71
+ assert_equal expected_lines, stderr_lines.size
71
72
  assert_equal commit_msg, stderr_lines[0..1].join("\n")
72
73
  assert_empty stderr_lines[2]
73
74
  assert_match(/\A1: Error: /, stderr_lines[3])
74
75
  assert_match(/\A1: Error: /, stderr_lines[4])
75
76
  assert_match(/\A2: Error: /, stderr_lines[5])
76
- assert_empty stderr_lines[6]
77
- assert_equal "Force commit? [y/n] ", stderr_lines[7]
77
+ if interactive
78
+ assert_empty stderr_lines[6]
79
+ assert_equal "Force commit? [y/n] ", stderr_lines[7]
80
+ end
81
+ end
82
+
83
+ def fake_tty(text)
84
+ StringIO.new(text).tap do |stringio|
85
+ def stringio.tty?
86
+ true
87
+ end
88
+ end
78
89
  end
79
90
 
80
91
  describe "user does not force commit" do
81
- let(:stdin) { StringIO.new("n") }
92
+ let(:stdin) { fake_tty("n") }
82
93
  it "prints errors to stderr and rejects commit" do
83
94
  assert_equal FitCommit::Runner::EXIT_CODE_REJECT_COMMIT, call_runner
84
95
  assert_error_output
85
96
  end
86
97
  end
87
98
  describe "user forces commit" do
88
- let(:stdin) { StringIO.new("y") }
99
+ let(:stdin) { fake_tty("y") }
89
100
  it "prints errors to stderr and allows commit" do
90
101
  assert_equal FitCommit::Runner::EXIT_CODE_ALLOW_COMMIT, call_runner
91
102
  assert_error_output
92
103
  end
93
104
  end
105
+ describe "TTY not available" do
106
+ let(:stdin) { StringIO.new("") }
107
+ it "prints errors to stderr and rejects commit" do
108
+ assert_equal FitCommit::Runner::EXIT_CODE_REJECT_COMMIT, call_runner
109
+ assert_error_output(interactive: false)
110
+ end
111
+ end
94
112
  end
95
113
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fit-commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Foley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-21 00:00:00.000000000 Z
11
+ date: 2015-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: swearjar
@@ -52,8 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.4'
55
- description: A Git hook to validate your commit messages, based largely on Tim Pope's
56
- authoritative guide.
55
+ description: A Git hook to validate your commit messages based on community standards.
57
56
  email:
58
57
  - foley3@gmail.com
59
58
  executables: