File tree 7 files changed +77
-3
lines changed
7 files changed +77
-3
lines changed Original file line number Diff line number Diff line change 10
10
` required_executable ` option on the JsHint and Jscs pre-commit hooks
11
11
* Add pre-commit hooks for [ standard] ( https://github.com/feross/standard ) and
12
12
[ semistandard] ( https://github.com/Flet/semistandard ) JavaScript linters
13
- * Add support for ` post-commit ` and ` post-merge ` hooks
13
+ * Add support for ` post-commit ` , ` post-merge ` , and ` post-rewrite ` hooks
14
14
* Add ` GitGuilt ` ` post-commit ` hook to display changes in blame ownership for
15
15
modified files
16
16
* Change behavior of configuration options containing array values to always
Original file line number Diff line number Diff line change @@ -306,3 +306,9 @@ PostCommit:
306
306
required_executable : ' git-guilt'
307
307
flags : ['HEAD~', 'HEAD']
308
308
install_command : ' npm install -g git-guilt'
309
+
310
+ # Hooks that run every time a commit is modified by an amend or rebase.
311
+ PostRewrite :
312
+ ALL :
313
+ requires_files : false
314
+ quiet : false
Original file line number Diff line number Diff line change
1
+ require 'forwardable'
2
+
3
+ module Overcommit ::Hook ::PostRewrite
4
+ # Functionality common to all post-rewrite hooks.
5
+ class Base < Overcommit ::Hook ::Base
6
+ extend Forwardable
7
+
8
+ def_delegators :@context , :amend? , :rebase?
9
+ end
10
+ end
Original file line number Diff line number Diff line change
1
+ module Overcommit ::HookContext
2
+ # Contains helpers for contextual information used by post-rewrite hooks.
3
+ class PostRewrite < Base
4
+ # Returns whether this post-rewrite was triggered by `git commit --amend`.
5
+ #
6
+ # @return [true,false]
7
+ def amend?
8
+ @args [ 0 ] == 'amend'
9
+ end
10
+
11
+ # Returns whether this post-rewrite was triggered by `git rebase`.
12
+ #
13
+ # @return [true,false]
14
+ def rebase?
15
+ @args [ 0 ] == 'rebase'
16
+ end
17
+ end
18
+ end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+ require 'overcommit/hook_context/post_rewrite'
3
+
4
+ describe Overcommit ::HookContext ::PostRewrite do
5
+ let ( :config ) { double ( 'config' ) }
6
+ let ( :context ) { described_class . new ( config , args ) }
7
+
8
+ describe '#amend?' do
9
+ subject { context . amend? }
10
+
11
+ context 'when rewrite was triggered by amend' do
12
+ let ( :args ) { [ 'amend' ] }
13
+
14
+ it { should == true }
15
+ end
16
+
17
+ context 'when rewrite was triggered by rebase' do
18
+ let ( :args ) { [ 'rebase' ] }
19
+
20
+ it { should == false }
21
+ end
22
+ end
23
+
24
+ describe '#rebase?' do
25
+ subject { context . rebase? }
26
+
27
+ context 'when rewrite was triggered by amend' do
28
+ let ( :args ) { [ 'amend' ] }
29
+
30
+ it { should == false }
31
+ end
32
+
33
+ context 'when rewrite was triggered by rebase' do
34
+ let ( :args ) { [ 'rebase' ] }
35
+
36
+ it { should == true }
37
+ end
38
+ end
39
+ end
Original file line number Diff line number Diff line change 108
108
describe '.supported_hook_types' do
109
109
subject { described_class . supported_hook_types }
110
110
111
- it { should =~ %w[ commit-msg pre-commit post-checkout post-commit post-merge ] }
111
+ it { should =~ %w[ commit-msg pre-commit post-checkout post-commit post-merge post-rewrite ] }
112
112
end
113
113
114
114
describe '.supported_hook_type_classes' do
115
115
subject { described_class . supported_hook_type_classes }
116
116
117
- it { should =~ %w[ CommitMsg PreCommit PostCheckout PostCommit PostMerge ] }
117
+ it { should =~ %w[ CommitMsg PreCommit PostCheckout PostCommit PostMerge PostRewrite ] }
118
118
end
119
119
120
120
describe '.execute' do
Original file line number Diff line number Diff line change
1
+ overcommit-hook
You can’t perform that action at this time.
0 commit comments