Last active
January 13, 2021 08:22
-
-
Save eriwen/5193583 to your computer and use it in GitHub Desktop.
Pre-commit git hook for tracking new TODO/FIXME comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
$refname = ARGV[0] | |
$oldrev = ARGV[1] | |
$newrev = ARGV[2] | |
def tasks | |
puts 'Checking TODOs...' | |
todo_pattern = /^\s*\+\s*([\/\#]+|<\!\-\-)\s*(FIXME|TODO)\W*([\s\w]+)(\-\->)?$/ | |
# Find task-oriented comments added with this commit | |
diff_lines = `git diff-index -p -w --ignore-submodules -G"FIXME|TODO" HEAD`.split("\n") | |
diff_lines.each do |line| | |
if todo_pattern.match(line) | |
# This simply prints them, but you could do something fancier here | |
puts "#{$2}: #{$3}" | |
end | |
end | |
puts "\n" | |
end | |
tasks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment