gnustavo / Git-Hooks

Framework for implementing Git (and Gerrit) hooks
http://search.cpan.org/dist/Git-Hooks/
41 stars 17 forks source link

COMMIT_MSG working anyway #30

Closed JJ closed 8 years ago

JJ commented 8 years ago

This should fail the commit

#!/usr/bin/env perl

use strict;
use warnings;

use Git::Hooks;

COMMIT_MSG {
    my ($git, $commit_msg_file) = @_;
    print "Ready to fail\n";
    return 0;
};

run_hook($0, @ARGV);

But it does not:

$ git commit -am "This should fail"         
Checking commit-msg_error.pl  ✓
Ready to fail
[master 7b95273] This should fail
 1 file changed, 1 deletion(-)

Am I missing something? Shouldn't this return 0 with failure? It works even if it says 1, anyway.

This would be version 1.0.1, BTW. As you also see, there's a prepare-commit-msg hook running that is successful. But even all by itself it fails to fail, so that shouldn't be an issue.

gnustavo commented 8 years ago

Juan, this is a bug in Git::Hooks. I'll try to fix it today. However, you may force it to fail by replacing the "print" call by something like this:

$git->error('COMMIT-MSG', "Ready fo fail");

Please, let me know if it works.

I'll let you know when I release a fix for this.

Thanks!

JJ commented 8 years ago

Thanks! If you give me a hint of where to look, I might lend you a hand...

gnustavo commented 8 years ago

Thanks, Juan. I just released v1.14.1 which should appear on CPAN shortly. Please, give it a try and tell me if it works for you.

JJ commented 8 years ago

:+1: Thanks!