alphapapa/magit-todos

Branch diff scanner

alphapapa opened this issue · 4 comments

Prototype code for idea mentioned by @arronmabrey here: tarsius/hl-todo#41

Please see the branch referenced below. The new command magit-todos-toggle-branch-diff (bound to b with point on a TODO section heading) enables branch-local task lists in a Magit buffer.

This seems to work pretty well now. There's only one problem: while it's easy to get a diff showing one of these three things, as explained in the git diff man page:

               $ git diff            (1)
               $ git diff --cached   (2)
               $ git diff HEAD       (3)

           1. Changes in the working tree not yet staged for the next commit.
           2. Changes between the index and your last commit; what you would be committing if you run "git commit" witho
           3. Changes in the working tree since your last commit; what you would be committing if you run "git commit -a"

I can't find a way to get all three in a single diff. I tried git diff master..HEAD, but it does not show changes that are only in the working tree, nor does it show changes in the index.

So while this does fulfill the requirements of @arronmabrey, it doesn't show uncommitted TODOs in the working tree, which may be less useful. It's also likely to confuse users, since that's not how the other scanners work.

I could run git diff 3 times with different arguments and concat or dedupe the output, but that doesn't seem like a great idea.

@tarsius Do you know of the best way to do this?

git diff HEAD^ shows the changes in the working tree and HEAD, but it doesn't show changes in the index that were undone in the working tree or changes in HEAD that were undone in the index or the working tree. Maybe that is okay.

@tarsius Thank you, that seems like a good compromise and works well!

By the way, it does appear to show changes in HEAD that are removed in the index or working tree. e.g.

  1. Make new branch.
  2. Add new commit that adds a line.
  3. git diff HEAD^ shows the line.
  4. Remove line from working tree.
  5. git diff HEAD^ doesn't show the line.
  6. Stage removal of line.
  7. git diff HEAD^ doesn't show the line.

I'm happy with that. :)

It seems to be working well, so I merged this feature to master. Please let me know if you find any issues.