Skip to content

Instantly share code, notes, and snippets.

@eriwen
Last active January 13, 2021 08:22
Show Gist options
  • Save eriwen/5193583 to your computer and use it in GitHub Desktop.
Save eriwen/5193583 to your computer and use it in GitHub Desktop.
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