Hi
Still not working.
I tried by keeping die("Kaboom!\n"); in the pre-receive file.
but still it pushed my commit, it didn't fail.
see the output below when I tried individually ./pre-receive it printed
Kaboom and it came out, but when I try to push it didnt.$ ./pre-receive Kaboom! mvari (GIT_DIR!) $ cd ../.. mvari $ git add gitHooks/pre-receive mvari $ git commit -m "hook test" [feature/DD-157-pre-recieve-hook-to-force-jira-ticket 2341484] hook test Committer: Mrudula Vari <[email protected]> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly: git config --global user.name "Your Name" git config --global user.email [email protected] After doing this, you may fix the identity used for this commit with: git commit --amend --reset-author 1 file changed, 1 insertion(+) mvari $ git push origin feature/DD-157-pre-recieve-hook-to-force-jira-ticket Counting objects: 4, done. Delta compression using up to 2 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 376 bytes | 0 bytes/s, done. Total 4 (delta 3), reused 0 (delta 0) remote: remote: Create pull request for feature/DD-157-pre-recieve-hook-to-force-jira-ticket: remote: https://bitbucket.fitchratings.com/projects/FRC/repos/fitchgroup_confluence_cookbook/compare/commits?sourceBranch=refs/heads/feature/DD-157-pre-recieve-hook-to-force-jira-ticket remote: To https://bitbucket.fitchratings.com/scm/frc/fitchgroup_confluence_cookbook.git 03d020d..2341484 feature/DD-157-pre-recieve-hook-to-force-jira-ticket -> feature/DD-157-pre-recieve-hook-to-force-jira-ticket mvari $ On Wed, Dec 7, 2016 at 5:04 PM, Konstantin Khomoutov < [email protected]> wrote: > 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.
