martes, 16 de agosto de 2011

git push -f to master and you're a dead man

Just came back from the half of my holidays, and came with a quite long TODO list.

One item of the list was a wrapper for git that avoids pushing -f the master branch.

At my new $job (yes, I changed again, you'll be noticed properly when I have more time to write), we use a minimal version of git-flow and we run tests on remote (personal) branches.

That means that sometimes, you have to git push -f to your personal remote branch, and possibly delete history. There's no problem if you do it in your personal branch, but as dumbans we err, and myself, being new to all this git fancy stuff, I was a bit worried about it.

I've come with a solution that should work fairly well and transparently. A wrapper for git that nops dangerous commands.

It's perl, and here it is.

Despite being destructive, I like the equals method, kind of lispy, but using shift as a car/cdr solution.

To make the wrapper work, rename it to 'git', make it executable, and put it somewhere in your path, before /usr/bin/git executable.