Skip to content

Instantly share code, notes, and snippets.

Last active January 13, 2021 08:22
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Pre-commit git hook for tracking new TODO/FIXME comments
$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}"
puts "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment