On Wed, 7 Dec 2016 02:58:22 -0800 (PST)
[email protected] wrote:

> I tried the below,
> when I am individually running ./pre-receive its working, but when I
> try to push even If am not giving jirs issue its pushing to remote.
> Please help me on this

Good to know you actually tried to solve it; congrats with this!

The way to debug such things out is to start small: in the end, you
want your hook to fail the push operation?  OK, let's just test
that: what happens if you put

  die("Kaboom!\n");

right after the shebang line (that "#!/usr/bin/perl" thing)?

As you can see, it should do two things:

1) Write "Kaboom" + LF to the standard error stream.
2) Die with code 255 preventing Git from carrying out its task.

If it will still not work, you have a problem actually enabling your
hook; or something else preventing it from running.

If it works, you have an error in the script's logic.

All in all, let's try what I suggested first and see what happens.

> 
> #!/usr/bin/perl
>  
> # Force JIRA ticket in commit messages
>  
> my $errors = 0;
> 
>   chomp(my @commits = `git rev-parse --abbrev-ref HEAD`);
>   if ($?) {
>     warn "git rev-list $old..$new failed\n";
>     ++$errors, next;
>   }
>  
>   foreach my $sha1 (@commits) {
>     my $msg = `git cat-file commit $sha1`;
>     if ($?) {
>       warn "git cat-file commit $sha1 failed";
>       ++$errors, next;
>     }
>  
>     $msg =~ s/\A.+? ^$ \s+//smx;
>     unless ($msg =~ /^[A-Z]+-[0-9]/) {
>       warn "The git commit message for $sha1\n";
>       warn "must be prepended with a valid JIRA key.\n";
>       warn "Use CAPS for the project key.\n";
>       warn "For example:\n";
>       warn "    KEY-123: $msg\n";
>       warn "Use \"git commit --amend -m\" to fix the message or\n";
>       warn "\"git rebase\" if you are pushing multiple commits.\n";
>  
>       ++$errors, next;
>     }
>   }
> 
>  
> exit $errors == 0 ? 0 : 1;
[...]

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to