zegl/extremely-linear

Prevent running if the git index is dirty (contains changes)

Closed this issue · 4 comments

In the readme, it says git-linearize is production ready. However, this ¿bug? is quite severe I would say:

  1. Install git-linearize as post-commit hook
  2. Do quite some work, where you do different kinds of work in different files
  3. Add and commit one file with a nice description.
  4. ALL OTHER CHANGES YOU'VE MADE WILL BE DESTROYED

What could be done I think, is to check for a dirty index in the post-commit hook:
git diff-index --quiet HEAD && git-linearize
git diff-index will return non-zero exit if there are any changes to be committed, so it will not run git-linearize until all changes are committed.

zegl commented

To be fair, the README says "100% production ready, 0% recommended", followed by "Create a backup first!" 😄

It's a good suggestion tough. git-linearize could check the index as you suggested and abort if it's dirty.

I was being a bit funny with the production-readyness, I know it's not meant to be run in production. However, creating a backup and using it in a post-commit hook are kind of contradicting. I've made a small PR with a hook that I've made in the repo where everything was DESTROYED.

zegl commented

Fixed by #10

Ah, beautiful! works like a charm!