Skip to content

Instantly share code, notes, and snippets.

@eriwen eriwen/pre-commit
Last active Dec 3, 2019

Embed
What would you like to do?
Pre-commit git hook for tracking new TODO/FIXME comments
#!/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
You can’t perform that action at this time.