App::GitHooks::Plugin::ForceBranchNamePattern - Require branch names to match a given pattern before they can be pushed to the origin.
For example, if you define in your .githooksrc file the following:
[ForceBranchNamePattern] branch_name_pattern = /^[a-zA-Z0-9]+$/
Then a branch named TestBranch can be pushed to the origin, but not one named test_branch.
TestBranch
test_branch
A practical use of this plugin is making Puppet environment out of git branches, since Puppet environment names must be strictly alphanumeric.
Version 1.1.3
This plugin relies on the pre-push hook, which is only available as of git v1.8.2.
This plugin supports the following options in your .githooksrc file.
.githooksrc
project_prefixes = OPS, DEV [ForceBranchNamePattern] branch_name_pattern = /^[a-zA-Z0-9]+$/
Optional, a comma-separated list of project prefixes in case you want to use them in the branch_name_pattern regex.
branch_name_pattern
This setting must be added in the main section of your .githooksrc file, as it is used by multiple plugins.
project_prefixes = OPS, DEV
A regular expression that will be used to check branch names before allowing you to push them to the origin.
This setting must be added in the [ForceBranchNamePattern] section of your .githooksrc file.
[ForceBranchNamePattern]
# Require alphanumeric branches only. branch_name_pattern = /^[a-zA-Z0-9]+$/ # Require branches to start with a JIRA ticket ID followed by an underscore. branch_name_pattern = /^DEV-\d+_/ # Require branches to start with a JIRA ticket ID followed by an underscore, # but they can have an optional user prefix. branch_name_pattern = /^(?:[^\/]+\/)?DEV-\d+_/ # Re-use "project_prefixes" defined in the main section of the config. branch_name_pattern = /^$project_prefixes-\d+_/
Code to execute as part of the pre-push hook.
my $plugin_return_code = App::GitHooks::Plugin::ForceBranchNamePattern->run_pre_push( app => $app, stdin => $stdin, );
Arguments:
$app (mandatory)
An App::GitHooks object.
App::GitHooks
$stdin (mandatory)
The content provided by git on stdin, corresponding to a list of references being pushed.
Retrieve a list of the branches being pushed with git push.
git push
my $tags = App::GitHooks::Plugin::ForceBranchNamePattern::get_pushed_branch_names( $app, $stdin, );
Please report any bugs or feature requests through the web interface at https://github.com/guillaumeaubert/App-GitHooks-Plugin-ForceBranchNamePattern/issues/new. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc App::GitHooks::Plugin::ForceBranchNamePattern
You can also look for information at:
GitHub's request tracker
https://github.com/guillaumeaubert/App-GitHooks-Plugin-ForceBranchNamePattern/issues
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/app-githooks-plugin-forcebranchnamepattern
CPAN Ratings
http://cpanratings.perl.org/d/app-githooks-plugin-forcebranchnamepattern
MetaCPAN
https://metacpan.org/release/App-GitHooks-Plugin-ForceBranchNamePattern
Guillaume Aubert, <aubertg at cpan.org>.
<aubertg at cpan.org>
Copyright 2015-2016 Guillaume Aubert.
This code is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the LICENSE file for more details.
To install App::GitHooks::Plugin::ForceBranchNamePattern, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::GitHooks::Plugin::ForceBranchNamePattern
CPAN shell
perl -MCPAN -e shell install App::GitHooks::Plugin::ForceBranchNamePattern
For more information on module installation, please visit the detailed CPAN module installation guide.