Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script to find all TODO comments created on a git branch?

Tags:

git

todo

I have a feature branch that's grown quite large. There are quite a few lingering TODO comments in our code, but I'd like to find all TODOs added to the code (and not removed yet) on commits not yet merged into master. How might I go about that?

like image 448
Ben Dilts Avatar asked Jun 13 '14 19:06

Ben Dilts


People also ask

How do I view all branches in Git?

You can view all created branches using the git branch command. It will show a list of all branches and mark the current branch with an asterisk and highlight it in green. In a single command, you can create and switch to a new branch right away.

How to list all commits in a git repository?

The command to list all commits is git rev- list --remotes `git rev-list` list commit objects in reverse chronological order. The key option is `–remotes`.

How does Git REBASE delete Todo commits?

If you're doing your housekeeping and git rebase -i the branch every time before you push, git notices that these TODO commits are empty and automatically comments them out from the list of commits to keep. You still get to review the TODO list, but you don't have to worry about cleaning up these commits manually.

How do I keep track of personal Todos in Git?

You can keep quick, short-lived personal TODOs as empty commits in the current git branch ( original tweet ): <i>You can save this either as a shell function or git-todo executable.</i> This records an empty commit prefixed with "TODO". This way git log will remind you both what you have done on this branch and what you need to be doing:


1 Answers

You can use this as an Git alias:

git --no-pager diff -U0 master | \
grep '^+.*TODO' | \
sed 's/^+//' | \
git --no-pager grep -nFf - 2> /dev/null

It shows the added/modified TODO lines of the current branch (compared to master), but you have to git add before using it (because of git grep).

It can be even more usefull if you add it to the status alias, thus you would be sure that no TODOs remaining when you see the status.

[alias]
  s = "!sh -c ' \
    [ $GIT_PREFIX ] && cd $GIT_PREFIX; \
    git status --short --branch $*; \
    git --no-pager diff -U0 master | \
    grep \"^+.*TODO\" | \
    sed \"s/^+//\" | \
    git --no-pager grep -nFf - 2> /dev/null' -"

Example output:

$ git s
## my-branch...origin/my-branch [ahead 2]
 M README.adoc
README.adoc:12: // TODO: Add screencast
README.adoc:26: // TODO: Advertise Asciidoctor
like image 132
bimlas Avatar answered Sep 20 '22 08:09

bimlas