Git hook scripts are not executing

Miscellaneous

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community

Stash relies on hook scripts that are installed into each repository (and managed by the system) to provide change information that, in turn, allows it to index JIRA issues, update pull requests and check branch permissions, for instance.

If the hooks are not installed correctly, or are damaged, these required callbacks do not happen and the functionality associated with them fails.

Symptoms

When git hooks are not executing, Stash does not detect changes to a repository and as a consequence:

  • Newly created repositories stay stuck in the 'empty repository' screen after changes have been pushed to the repository.
  • Branch permissions are not applied.
  • JIRA issue keys are not detected in pushed commits. As a result no JIRA issue links are displayed for the commits and the commits do not show up on the JIRA issue.
  • Fork synchronisation is not triggered.
  • Caches are not cleared and cloning a repository can return stale data.

Causes and Resolutions

The git callback hooks are not installed correctly, or are damaged, these required callbacks do not happen and the functionality associated with them fails.

Hook Scripts are Missing

Stash requires certain Git hooks to be installed into each repository for it to function correctly. But in this case many of the repositories are 'corrupt'. The following snippet from the application-properties/application.xml file, produced by the Support Tools Plugin, is an example of the files that need to be installed. If these entries are missing, hooks will not be run.

<hook-files>
  <hook-file>
    <path>/var/stash-data/data/repositories/1/hooks/post-receive</path>
  </hook-file>
  <hook-file>
    <path>/var/stash-data/data/repositories/1/hooks/pre-receive.d/20_stash_callback</path>
  </hook-file>
  <hook-file>
    <path>/var/stash-data/data/repositories/1/hooks/post-receive.d/20_stash_callback</path>
  </hook-file>
  <hook-file>
    <path>/var/stash-data/data/repositories/1/hooks/pre-receive</path>
  </hook-file>
</hook-files>

Resolution

Affected repositories can be fixed by copying the 4 missing scripts - post-receive, post-receive.d/20_stash_callback, pre-receive and  pre-receive.d/20_stash_callback - into the repository under <STASH_HOME>/data/repositories/<Repo_ID>/hooks directory. Ensure the scripts are executable after they are copied. To identify which repository ID maps to your affected repository, refer to this guide.

Hook Scripts are not Executable

Even if the required hook scripts are installed, they can only be run if they are executable. This can be checked with the same application-properties/application.xml, generated by the Support Tools Plugin, by looking for lines like the following. Notice that isExecutable shows false for the scripts.

<hook-files>
  <hook-file>
    <path>/var/stash-data/data/repositories/1/hooks/post-receive</path>
    <size>426</size>
    <isExecutable>false</isExecutable>
  </hook-file>
  <hook-file>
    <path>/var/stash-data/data/repositories/1/hooks/post-receive.d/20_stash_callback</path>
    <size>412</size>
    <isExecutable>false</isExecutable>
  </hook-file>
</hook-files>

Resolution

  1. Affected repositories can be fixed by running chmod u+x on non-executable scripts. The exact path to each script is included in the XML.
  2. It is also common that the mount line for the Stash volume does not have an executable flag. You should mount the partition with an executable flag. Example of a wrong mount:

    $ mount | grep stash
    /dev/sdb1 /stash ext4 rw,user 0 0

    A demonstration with a temporary ramdisk:

    A) Mounting without exec, giving a script exec permissions and trying to execute it - this won't work

    > mkdir /tmp/ramdisk && sudo mount -t tmpfs -o rw,user tmpfs /tmp/ramdisk/
    > echo "echo no exec' >> /tmp/ramdisk/ && chmod a+x /tmp/ramdisk/test
    > /tmp/ramdisk/test
    -bash: /tmp/ramdisk/test: Permission denied
    > sudo umount /tmp/ramdisk/

    B) Mounting with exec, giving a script exec permissions and trying to execute it - this will work:

    > mkdir /tmp/ramdisk && sudo mount -t tmpfs -o rw,user,exec tmpfs /tmp/ramdisk/
    > echo "echo hello' >> /tmp/ramdisk/ && chmod a+x /tmp/ramdisk/test
    > /tmp/ramdisk/test
    hello
    > sudo umount /tmp/ramdisk/
Last modified on Dec 17, 2014

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.