File tree 5 files changed +52
-3
lines changed
lib/overcommit/hook/post_checkout
spec/overcommit/hook/post_checkout
5 files changed +52
-3
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ Display when a hook has been explicitly skipped when it would otherwise run
22
22
Display when no applicable hooks ran (e.g. instead of "All pre-commit checks passed")
23
23
Add pre-commit check ensuring Gemfile.lock matches Gemfile (unless in .gitignore)
24
24
Add check for https://github.com/mdevils/node-jscs
25
+ Add post-checkout check for asking to update git submodules
25
26
26
27
27
28
Allow features of hooks to be customized (stealth, required, etc.)
Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ post_checkout:
20
20
include :
21
21
- ' Gemfile'
22
22
- ' Gemfile.lock'
23
+ IndexTags :
24
+ description : ' Indexing source code tags'
23
25
24
26
# Hooks that are run after `git commit` is executed, before the commit message
25
27
# editor is displayed. These hooks are ideal for syntax checkers, linters, and
Original file line number Diff line number Diff line change
1
+ module Overcommit ::Hook ::PostCheckout
2
+ # Scans source code each time HEAD changes to generate an up-to-date index of
3
+ # all function/variable definitions, etc.
4
+ class IndexTags < Base
5
+ def run
6
+ unless in_path? ( 'ctags' )
7
+ return :good # Silently ignore
8
+ end
9
+
10
+ index_tags_in_background
11
+
12
+ :good
13
+ end
14
+
15
+ private
16
+
17
+ SCRIPT_LOCATION = Overcommit ::Utils . script_path ( 'index-tags' )
18
+
19
+ def index_tags_in_background
20
+ # TODO: come up with Ruby 1.8-friendly way to do this
21
+ Process . detach ( Process . spawn ( SCRIPT_LOCATION ) )
22
+ end
23
+ end
24
+ end
Original file line number Diff line number Diff line change 6
6
7
7
set -e
8
8
9
- ctags --version & > /dev/null || exit 0
10
-
11
9
trap " rm -f .git/tags.$$ " EXIT
12
10
err_file=.git/ctags.err
13
11
if ctags --tag-relative -Rf.git/tags.$$ --exclude=.git " $@ " 2> ${err_file} ; then
14
12
mv .git/tags.$$ .git/tags
15
- [ -e ${err_file} ] && rm ${err_file}
13
+ [ -e ${err_file} ] && rm -f ${err_file}
16
14
else
17
15
# Ignore STDERR unless `ctags` returned a non-zero exit code
18
16
cat ${err_file}
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe Overcommit ::Hook ::PostCheckout ::IndexTags do
4
+ let ( :config ) { Overcommit ::ConfigurationLoader . default_configuration }
5
+ let ( :context ) { double ( 'context' ) }
6
+ let ( :subject ) { described_class . new ( config , context ) }
7
+
8
+ before do
9
+ subject . stub ( :in_path? ) . and_return ( installed )
10
+ subject . stub ( :index_tags_in_background )
11
+ end
12
+
13
+ context 'when ctags is not installed' do
14
+ let ( :installed ) { false }
15
+
16
+ it { should pass }
17
+ end
18
+
19
+ context 'when ctags is installed' do
20
+ let ( :installed ) { true }
21
+
22
+ it { should pass }
23
+ end
24
+ end
You can’t perform that action at this time.
0 commit comments