Skip to content

Commit 88cd039

Browse files
committed
Add IndexTags hook for post-{commit,merge,rewrite}
Add support for updating ctags all the time, based on an article from the illustrious Tim Pope: http://tbaggery.com/2011/08/08/effortless-ctags-with-git.html Change-Id: I8d515cd69ca80c35f760a1f1b7a7484ee1e40871 Reviewed-on: http://gerrit.causes.com/46993 Tested-by: jenkins <jenkins@brigade.com> Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
1 parent f2c65ef commit 88cd039

File tree

12 files changed

+103
-16
lines changed

12 files changed

+103
-16
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
replace the old value instead of appending to it
1818
* Add `execute_in_background` helper to provide a standardized way to start
1919
long-running processes without blocking the hook run
20+
* Add `IndexTags` hook for `post-commit`, `post-merge`, and `post-rewrite`
21+
hook types so tags index can always be kept up to date via `ctags`
2022

2123
## 0.22.0
2224

config/default.yml

+16
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ PostCheckout:
291291
IndexTags:
292292
enabled: false
293293
description: 'Generating tags file from source'
294+
required_executable: 'ctags'
294295

295296
# Hooks that run after a commit is created.
296297
PostCommit:
@@ -307,14 +308,29 @@ PostCommit:
307308
flags: ['HEAD~', 'HEAD']
308309
install_command: 'npm install -g git-guilt'
309310

311+
IndexTags:
312+
enabled: false
313+
description: 'Generating tags file from source'
314+
required_executable: 'ctags'
315+
310316
# Hooks that run after `git merge` executes successfully (no merge conflicts).
311317
PostMerge:
312318
ALL:
313319
requires_files: false
314320
quiet: false
315321

322+
IndexTags:
323+
enabled: false
324+
description: 'Generating tags file from source'
325+
required_executable: 'ctags'
326+
316327
# Hooks that run after a commit is modified by an amend or rebase.
317328
PostRewrite:
318329
ALL:
319330
requires_files: false
320331
quiet: false
332+
333+
IndexTags:
334+
enabled: false
335+
description: 'Generating tags file from source'
336+
required_executable: 'ctags'

lib/overcommit/hook/post_checkout/index_tags.rb

-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ class IndexTags < Base
66
SCRIPT_LOCATION = Overcommit::Utils.script_path('index-tags')
77

88
def run
9-
unless in_path?('ctags')
10-
return :pass # Silently ignore
11-
end
12-
139
ctags_args = Array(config['ctags_arguments'])
1410
execute_in_background([SCRIPT_LOCATION] + ctags_args)
1511

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Overcommit::Hook::PostCommit
2+
# Updates ctags index for all source code in the repository.
3+
class IndexTags < Base
4+
# Location of the tag indexing script.
5+
SCRIPT_LOCATION = Overcommit::Utils.script_path('index-tags')
6+
7+
def run
8+
ctags_args = Array(config['ctags_arguments'])
9+
execute_in_background([SCRIPT_LOCATION] + ctags_args)
10+
11+
:pass
12+
end
13+
end
14+
end
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Overcommit::Hook::PostMerge
2+
# Updates ctags index for all source code in the repository.
3+
class IndexTags < Base
4+
# Location of the tag indexing script.
5+
SCRIPT_LOCATION = Overcommit::Utils.script_path('index-tags')
6+
7+
def run
8+
ctags_args = Array(config['ctags_arguments'])
9+
execute_in_background([SCRIPT_LOCATION] + ctags_args)
10+
11+
:pass
12+
end
13+
end
14+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Overcommit::Hook::PostRewrite
2+
# Updates ctags index for all source code in the repository.
3+
class IndexTags < Base
4+
# Location of the tag indexing script.
5+
SCRIPT_LOCATION = Overcommit::Utils.script_path('index-tags')
6+
7+
def run
8+
# Ignore unless this is a rebase (amends are covered by post-commit hook)
9+
return :pass unless rebase?
10+
11+
ctags_args = Array(config['ctags_arguments'])
12+
execute_in_background([SCRIPT_LOCATION] + ctags_args)
13+
14+
:pass
15+
end
16+
end
17+
end

spec/overcommit/hook/post_checkout/index_tags_spec.rb

+1-12
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,8 @@
66
subject { described_class.new(config, context) }
77

88
before do
9-
subject.stub(:in_path?).and_return(installed)
109
subject.stub(:execute_in_background)
1110
end
1211

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
12+
it { should pass }
2413
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PostCommit::IndexTags do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
before do
9+
subject.stub(:execute_in_background)
10+
end
11+
12+
it { should pass }
13+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PostMerge::IndexTags do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
before do
9+
subject.stub(:execute_in_background)
10+
end
11+
12+
it { should pass }
13+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PostMerge::IndexTags do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
before do
9+
subject.stub(:execute_in_background)
10+
end
11+
12+
it { should pass }
13+
end

0 commit comments

Comments
 (0)