The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

App::GitHooks::Plugin::ForceBranchNamePattern - Require branch names to match a given pattern before they can be pushed to the origin.

DESCRIPTION

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.

A practical use of this plugin is making Puppet environment out of git branches, since Puppet environment names must be strictly alphanumeric.

VERSION

Version 1.1.3

MINIMUM GIT VERSION

This plugin relies on the pre-push hook, which is only available as of git v1.8.2.

CONFIGURATION OPTIONS

This plugin supports the following options in your .githooksrc file.

        project_prefixes = OPS, DEV
        
        [ForceBranchNamePattern]
        branch_name_pattern = /^[a-zA-Z0-9]+$/

project_prefixes

Optional, a comma-separated list of project prefixes in case you want to use them in the branch_name_pattern regex.

This setting must be added in the main section of your .githooksrc file, as it is used by multiple plugins.

        project_prefixes = OPS, DEV

branch_name_pattern

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.

        # 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+_/

METHODS

run_pre_push()

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.

  • $stdin (mandatory)

    The content provided by git on stdin, corresponding to a list of references being pushed.

FUNCTIONS

get_pushed_branch_names()

Retrieve a list of the branches being pushed with git push.

        my $tags = App::GitHooks::Plugin::ForceBranchNamePattern::get_pushed_branch_names(
                $app,
                $stdin,
        );

Arguments:

  • $app (mandatory)

    An App::GitHooks object.

  • $stdin (mandatory)

    The content provided by git on stdin, corresponding to a list of references being pushed.

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

        perldoc App::GitHooks::Plugin::ForceBranchNamePattern

You can also look for information at:

AUTHOR

Guillaume Aubert, <aubertg at cpan.org>.

COPYRIGHT & LICENSE

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.