Git::Hooks::CheckRewrite - Git::Hooks plugin for checking against unsafe rewrites
version 0.052
This Git::Hooks plugin hooks itself to the pre-rebase hook to guarantee that it is safe in the sense that no rewritten commit is reachable by other branch than the one being rebased.
It also hooks itself to the pre-commit and the post-commit hooks to detect unsafe git commit --amend commands after the fact. An amend is unsafe if the original commit is still reachable by any branch after being amended. Unfortunately git still does not provide a way to detect unsafe amends before committing them.
To enable it you should add it to the githooks.plugin configuration option:
git config --add githooks.plugin CheckRewrite
There's no configuration needed or provided.
This module exports the following routines that can be used directly without using all of Git::Hooks infrastructure.
This is the routine used to implement the pre-commit hook. It needs a Git::More object. It simply record the original commit id and its parents in a file called GITHOOKS_CHECKREWRITE inside the git repository directory
pre-commit
Git::More
GITHOOKS_CHECKREWRITE
This is the routine used to implement the post-commit hook. It needs a Git::More object. It reads the original commit id and its parents from a file called GITHOOKS_CHECKREWRITE inside the git repository directory, which must have been created by the record_commit_parents routine during the pre-commit hook. Using this information it detects if this was an unsafe amend and tells the user so.
post-commit
record_commit_parents
This is the routine used to implement the pre-rebase hook. It needs a Git::More object, the name of the upstream branch onto which we're rebasing and the name of the branch being rebased. (If BRANCH is undefined it means that we're rebasing the current branch.
pre-rebase
The routine dies with a suitable message if it detects that it will be an unsafe rebase.
Here are some references about what it means for a rewrite to be unsafe and how to go about detecting them in git:
http://git.661346.n2.nabble.com/pre-rebase-safety-hook-td1614613.html
http://git.apache.org/xmlbeans.git/hooks/pre-rebase.sample
http://www.mentby.com/Group/git/rfc-pre-rebase-refuse-to-rewrite-commits-that-are-reachable-from-upstream.html
http://git.661346.n2.nabble.com/RFD-Rewriting-safety-warn-before-when-rewriting-published-history-td7254708.html
Gustavo L. de M. Chaves <gnustavo@cpan.org>
This software is copyright (c) 2014 by CPqD <www.cpqd.com.br>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Git::Hooks, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Git::Hooks
CPAN shell
perl -MCPAN -e shell install Git::Hooks
For more information on module installation, please visit the detailed CPAN module installation guide.