0

I read up online that git hook accepts 3 arguments:

  1. the name of the ref being updated,

  2. the old object name stored in the ref,

  3. and the new object name to be stored in the ref.

I am trying to access these arguments but it's empty. What could be wrong here?

#!/bin/bash


echo $@
refname="$1"
oldrev="$2"
newrev="$3"

Based on the comments, I tried adding an echo statement echo "In update hook: Args:$@" and heres the output that I see:

$git push
Counting objects: 6, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 563 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 1 (delta 0)
remote: In update hook: Args:
remote:
remote:
halfer
  • 19,824
  • 17
  • 99
  • 186
iDev
  • 2,163
  • 10
  • 39
  • 64
  • Hooks need to be executable, did you make sure to `chmod +x $yourscriptfile` ? Also, make sure to remove the `.sample` naming from the hook file you are trying to excute. – Bjoern Rennhak May 29 '18 at 19:45
  • 1
    Also, keep in mind some hooks don't receive arguments via the command line. See eg. https://stackoverflow.com/questions/3762084/git-empty-arguments-in-post-receive-hook – Bjoern Rennhak May 29 '18 at 19:52
  • 1
    @BjoernRennhak The OP talks about update hook so `$yourscriptfile` is actually `.git/hooks/update`. :-) [Docs say](https://git-scm.com/docs/githooks#update) it really receive 3 parameters at the command line. – phd May 29 '18 at 20:31
  • 1
    Have you put the script into `git/hooks/update` at the sever repo? Is it executable? Add an echo to verify it's really running, like `echo "In update hook. Args: $@"` – phd May 29 '18 at 20:34
  • 1
    I did add an echo statement and see that the hook is being triggered but the arguments are empty – iDev May 29 '18 at 21:31

1 Answers1

1

Thank you Bjoern for the reference link. Based on the link you provided, I am able to retreive the arguments:

Source: git: empty arguments in post-receive hook posted by estani

read oldrev newrev refname
echo "Old revision: $oldrev"
echo "New revision: $newrev"
echo "Reference name: $refname"
iDev
  • 2,163
  • 10
  • 39
  • 64