Skip to content

Commit 5f271a8

Browse files
committed
Add BundleInstall post-{commit,checkout,merge,rewrite} hooks
1 parent 728755f commit 5f271a8

File tree

10 files changed

+221
-0
lines changed

10 files changed

+221
-0
lines changed

config/default.yml

+48
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,18 @@ PostCheckout:
541541
flags: ['install']
542542
include: 'bower.json'
543543

544+
BundleInstall:
545+
enabled: false
546+
description: 'Installing Bundler dependencies'
547+
requires_files: true
548+
required_executable: 'bundle'
549+
install_command: 'gem install bundler'
550+
flags: ['install']
551+
include:
552+
- 'Gemfile'
553+
- 'Gemfile.lock'
554+
- '*.gemspec'
555+
544556
IndexTags:
545557
enabled: false
546558
description: 'Generating tags file from source'
@@ -579,6 +591,18 @@ PostCommit:
579591
flags: ['install']
580592
include: 'bower.json'
581593

594+
BundleInstall:
595+
enabled: false
596+
description: 'Installing Bundler dependencies'
597+
requires_files: true
598+
required_executable: 'bundle'
599+
install_command: 'gem install bundler'
600+
flags: ['install']
601+
include:
602+
- 'Gemfile'
603+
- 'Gemfile.lock'
604+
- '*.gemspec'
605+
582606
GitGuilt:
583607
enabled: false
584608
description: 'Calculating changes in blame since last commit'
@@ -624,6 +648,18 @@ PostMerge:
624648
flags: ['install']
625649
include: 'bower.json'
626650

651+
BundleInstall:
652+
enabled: false
653+
description: 'Installing Bundler dependencies'
654+
requires_files: true
655+
required_executable: 'bundle'
656+
install_command: 'gem install bundler'
657+
flags: ['install']
658+
include:
659+
- 'Gemfile'
660+
- 'Gemfile.lock'
661+
- '*.gemspec'
662+
627663
IndexTags:
628664
enabled: false
629665
description: 'Generating tags file from source'
@@ -661,6 +697,18 @@ PostRewrite:
661697
flags: ['install']
662698
include: 'bower.json'
663699

700+
BundleInstall:
701+
enabled: false
702+
description: 'Installing Bundler dependencies'
703+
requires_files: true
704+
required_executable: 'bundle'
705+
install_command: 'gem install bundler'
706+
flags: ['install']
707+
include:
708+
- 'Gemfile'
709+
- 'Gemfile.lock'
710+
- '*.gemspec'
711+
664712
IndexTags:
665713
enabled: false
666714
description: 'Generating tags file from source'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'overcommit/hook/shared/bundle_install'
2+
3+
module Overcommit::Hook::PostCheckout
4+
# Runs `bundle install` when a change is detected in the repository's
5+
# dependencies.
6+
#
7+
# @see {Overcommit::Hook::Shared::BundleInstall}
8+
class BundleInstall < Base
9+
include Overcommit::Hook::Shared::BundleInstall
10+
end
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'overcommit/hook/shared/bundle_install'
2+
3+
module Overcommit::Hook::PostCommit
4+
# Runs `bundle install` when a change is detected in the repository's
5+
# dependencies.
6+
#
7+
# @see {Overcommit::Hook::Shared::BundleInstall}
8+
class BundleInstall < Base
9+
include Overcommit::Hook::Shared::BundleInstall
10+
end
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'overcommit/hook/shared/bundle_install'
2+
3+
module Overcommit::Hook::PostMerge
4+
# Runs `bundle install` when a change is detected in the repository's
5+
# dependencies.
6+
#
7+
# @see {Overcommit::Hook::Shared::BundleInstall}
8+
class BundleInstall < Base
9+
include Overcommit::Hook::Shared::BundleInstall
10+
end
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'overcommit/hook/shared/bundle_install'
2+
3+
module Overcommit::Hook::PostRewrite
4+
# Runs `bundle install` when a change is detected in the repository's
5+
# dependencies.
6+
#
7+
# @see {Overcommit::Hook::Shared::BundleInstall}
8+
class BundleInstall < Base
9+
include Overcommit::Hook::Shared::BundleInstall
10+
end
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Overcommit::Hook::Shared
2+
# Shared code used by all BundleInstall hooks. Runs `bundle install` when a
3+
# change is detected in the repository's dependencies.
4+
#
5+
# @see http://bundler.io/
6+
module BundleInstall
7+
def run
8+
result = execute(command)
9+
return :fail, result.stdout unless result.success?
10+
:pass
11+
end
12+
end
13+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PostCheckout::BundleInstall do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
let(:result) { double('result') }
9+
10+
before do
11+
subject.stub(:execute).and_return(result)
12+
end
13+
14+
context 'when bundle install exits successfully' do
15+
before do
16+
result.stub(:success?).and_return(true)
17+
end
18+
19+
it { should pass }
20+
end
21+
22+
context 'when bundle install exits unsuccessfully' do
23+
before do
24+
result.stub(success?: false, stdout: 'Could not locate Gemfile or .bundle/ directory')
25+
end
26+
27+
it { should fail_hook }
28+
end
29+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PostCommit::BundleInstall do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
let(:result) { double('result') }
9+
10+
before do
11+
subject.stub(:execute).and_return(result)
12+
end
13+
14+
context 'when bundle install exits successfully' do
15+
before do
16+
result.stub(:success?).and_return(true)
17+
end
18+
19+
it { should pass }
20+
end
21+
22+
context 'when bundle install exits unsuccessfully' do
23+
before do
24+
result.stub(success?: false, stdout: 'Could not locate Gemfile or .bundle/ directory')
25+
end
26+
27+
it { should fail_hook }
28+
end
29+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PostMerge::BundleInstall do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
let(:result) { double('result') }
9+
10+
before do
11+
subject.stub(:execute).and_return(result)
12+
end
13+
14+
context 'when bundle install exits successfully' do
15+
before do
16+
result.stub(:success?).and_return(true)
17+
end
18+
19+
it { should pass }
20+
end
21+
22+
context 'when bundle install exits unsuccessfully' do
23+
before do
24+
result.stub(success?: false, stdout: 'Could not locate Gemfile or .bundle/ directory')
25+
end
26+
27+
it { should fail_hook }
28+
end
29+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PostRewrite::BundleInstall do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
let(:result) { double('result') }
9+
10+
before do
11+
subject.stub(:execute).and_return(result)
12+
end
13+
14+
context 'when bundle install exits successfully' do
15+
before do
16+
result.stub(:success?).and_return(true)
17+
end
18+
19+
it { should pass }
20+
end
21+
22+
context 'when bundle install exits unsuccessfully' do
23+
before do
24+
result.stub(success?: false, stdout: 'Could not locate Gemfile or .bundle/ directory')
25+
end
26+
27+
it { should fail_hook }
28+
end
29+
end

0 commit comments

Comments
 (0)