Skip to content

Commit 4b877c0

Browse files
committed
Correctly compute the changed files based on each git hook
* Also let `jt lint fast` (without extra argument) work and assume everything changed. * Notably avoids running checks when just rewording a commit and using pre-commit. * Git post-commit hooks seem unfortunately to not be able to see that no files changed when just rewording a commit or rebasing.
1 parent 68e94ad commit 4b877c0

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

tool/hooks/lint-check.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@
88
# cp tool/hooks/lint-check.sh .git/hooks/pre-push
99
# The choice is yours.
1010

11-
exec tool/jt.rb lint fast
11+
filename=$(basename "${BASH_SOURCE[0]}")
12+
13+
case "$filename" in
14+
pre-commit) exec tool/jt.rb lint fast HEAD ;;
15+
post-commit) exec tool/jt.rb lint fast HEAD^ ;;
16+
pre-push) exec tool/jt.rb lint fast origin/master ;;
17+
esac

tool/jt.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,14 +2386,11 @@ def format_specializations_arguments
23862386

23872387
def lint(*args)
23882388
fast = args.first == 'fast'
2389-
if fast
2390-
changed_files = `git diff --cached --name-only` # Only staged files in the git index
2391-
if changed_files.empty? # post-commit hook
2392-
changed_files = `git diff --cached --name-only HEAD^`
2393-
end
2394-
raise 'Could not list changed files' if changed_files.empty?
2389+
args.shift if fast
2390+
2391+
if fast and compare_to = args.shift
2392+
changed_files = `git diff --cached --name-only #{compare_to}`
23952393
exts_changed = changed_files.lines.map { |f| File.extname(f.strip) }.uniq
2396-
raise 'Could not list changed file extensions' if exts_changed.empty?
23972394
changed = -> ext { exts_changed.include?(ext) }
23982395
else
23992396
changed = -> _ext { true }

0 commit comments

Comments
 (0)