Skip to content

Commit 68de6c7

Browse files
sdsShane da Silva
authored and
Shane da Silva
committed
Add IndexTags post-checkout hook
Change-Id: Id7858b3f51fa320a6a10be78eecd602563fda6ac Reviewed-on: http://gerrit.causes.com/35566 Reviewed-by: Shane da Silva <shane@causes.com> Tested-by: Shane da Silva <shane@causes.com>
1 parent bf5a5dc commit 68de6c7

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed

TODO

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Display when a hook has been explicitly skipped when it would otherwise run
2222
Display when no applicable hooks ran (e.g. instead of "All pre-commit checks passed")
2323
Add pre-commit check ensuring Gemfile.lock matches Gemfile (unless in .gitignore)
2424
Add check for https://github.com/mdevils/node-jscs
25+
Add post-checkout check for asking to update git submodules
2526

2627

2728
Allow features of hooks to be customized (stealth, required, etc.)

config/default.yml

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ post_checkout:
2020
include:
2121
- 'Gemfile'
2222
- 'Gemfile.lock'
23+
IndexTags:
24+
description: 'Indexing source code tags'
2325

2426
# Hooks that are run after `git commit` is executed, before the commit message
2527
# editor is displayed. These hooks are ideal for syntax checkers, linters, and
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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

libexec/scripts/index-tags

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77
set -e
88

9-
ctags --version &> /dev/null || exit 0
10-
119
trap "rm -f .git/tags.$$" EXIT
1210
err_file=.git/ctags.err
1311
if ctags --tag-relative -Rf.git/tags.$$ --exclude=.git "$@" 2>${err_file}; then
1412
mv .git/tags.$$ .git/tags
15-
[ -e ${err_file} ] && rm ${err_file}
13+
[ -e ${err_file} ] && rm -f ${err_file}
1614
else
1715
# Ignore STDERR unless `ctags` returned a non-zero exit code
1816
cat ${err_file}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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

0 commit comments

Comments
 (0)