Reputation: 21441
I want to see all TODO comments that only I wrote and that exist in the current code base that is git managed.
What I've got so far is printing all TODO comments that I've ever created or modified during the complete git history: git log -p --author="My name" -S TODO | grep "\+.*TODO"
But this tool chain lists all TODO comments ever written, even those that I've already resolved and thus removed again from code.
What’s a suitable tool chain that can search the current code base line-by-line, check if it contains "TODO" and if this line was authored by me print those lines?
Upvotes: 27
Views: 11281
Reputation: 161
Small suggestion here that I just ran across, larger repo and some binary files. The xargs -ni git blame
section was causing an unexpected term with signal 13. I got around this by adding a -I
switch on the initial git grep.
FWIW here's full error (go go google)
xargs: git: terminated by signal 13
Here's an example I used (also removed grep for my mine as wanted to see all)
git grep -I -l TODO | xargs -n1 git blame -f -n -w | grep TODO | sed "s/.\{9\}//" | sed "s/(.*)[[:space:]]*//"
Upvotes: 4
Reputation: 561
I found that the user name can have spaces, so it's easier to filter by email address. Also, the @todo (lowercase) is my way of adding notes in docblocks, so I added the "ignore lower/upper case" flag. This is my solution:
git grep -il TODO | xargs -n1 git blame -M -f -e | grep -i TODO | grep $(git config user.email)
Upvotes: 5
Reputation: 21441
I want do add on aragaer's and Kyle's solution:
git grep -l TODO | xargs -n1 git blame -f -n -w | grep "$(git config user.name)" | grep TODO | sed "s/.\{9\}//" | sed "s/(.*)[[:space:]]*//"
This prints:
Cpp/CoolClass.cpp 123 //TODO: Do we really need this? Cpp/AnotherClass.cpp 42 //TODO: Do we miss something? Java/MyListener.java 23 //TODO: Optimize
Upvotes: 21
Reputation: 14144
Complete with using git config
to get your name:
git grep -l TODO | xargs -n1 git blame | grep "$(git config user.name)" | grep TODO
Upvotes: 2
Reputation: 17858
You can combine git blame
with grep.
Like this (not the best one, but should work)
git grep -l TODO | xargs -n1 git blame | grep 'Your name' | grep TODO
Improved versions might combine line numbers found by first grep with git blame
's ability to show only given lines.
Upvotes: 30