Skip to content

Migrating to version 2

Gustavo Chaves edited this page Jun 16, 2017 · 2 revisions

Introduction

Git::Hooks version 2 is a major new version and introduced a few incompatible changes mentioned below. Most of them affect only hook and plugin developers, but not users. As a user you'll be affected only if you use the Git::Hooks::CheckStructure plugin, which was removed from the distribution. If you depend on it, you may reimplement its checks using the Git::Hooks::CheckFile and the Git::Hooks::CheckReference plugins.

Hook developers must be aware of the fact that the hook functions now receive as their first argument a Git::Repository object with two plugins enabled: Git::Repository::Plugin::GitHooks and Git::Repository::Plugin::Log. Previously they received a Git::More object instead.

Most of the methods of the old Git::More object are implemented by the Git::Repository::Plugin::GitHooks plugin, so that you shouldn't need to change code that invoked them. Three methods changed, though: get_commit, get_commits, and get_affected_ref_commits. They previously returned naked hashes representing Git commits. Now they return proper Git::Repository::Log objects.

Since Git::More derived from the Git module if you relied on any of its methods you'll have to study how to reimplement them in terms of the Git::Repository methods. Probably the most frequently used method of Git is command to invoke a Git command. They can be replaced by Git::Repository's run method.

Plugin developers should be aware of some changes in the Git::Hooks module per se. It used to export some utility functions that were imported by using the :utils tag, like this:

use Git::Hooks qw/:DEFAULT :utils/;

The utility functions were: is_ref_enabled, im_memberof, match_user, im_admin, file_temp, eval_gitconfig, post_hook, redirect_output, and restore_output. These functions are now methods of the Git::Repository object with the Git::Repository::Plugin::GitHooks enabled. So, first you should simplify the line above like this:

use Git::Hooks;

And the functions should now be invoked as methods of the $git object, like this:

$git->is_ref_enabled($ref);
Clone this wiki locally