diekershoff.net

/pub/diekershoff/tobias

My .git/hooks for Friendica development

misc #friendica #git #composer Do 01 Februar 2018

Just wanted to write down the git hooks I'm using for Friendica development. Both scripts do belong into the .git/hooks directory of the Friendica repository you are using. Additionally they need to be executable.

pre-commit

To avoid PHP syntax errors I let git execute checks on all changed PHP files that should be committed.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#!/usr/bin/env
# inspired by this thread at Stack Overflow
# https://stackoverflow.com/questions/2412450/
git diff --cached --name-status | while read st file; do
        # skip deleted files
        if [ "$st" == 'D' ]; then continue; fi
        # do a check only on the php files
        if [[ "$file" =~ ".php" ]] && ! /usr/bin/php -l $file; then
                echo "PHP syntax check failed for file: $file"
                exit 1
        fi
done

post-merge

Since a couple of days now, the dependencies of Friendica were mostly moved from /library to composer to handle them. You don't need to install anything additionally as we ship a version of it adopted for our needs in /util.

While this has many advantages, it also has the drawback that one needs to update the files pulled in by composer manually after a change in the composer.lock file. For this I'm using the following script.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#!/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# forked by Gianluca Guarini
# phponly by Ivo Bathke ;)
# modified for Friendica by Tobias Diekershoff
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
        echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
# `composer install` if the `composer.lock` file gets changed
# to update all the php dependencies
check_run composer.lock "util/composer.phar install --no-dev"

As said above these scripts belong into .git/hooks/pre-commit and .git/hooks/post-merge and have to be chmod +xed so that git can automatically execute them.

HTH and happy hacking!


theme last update

november 2017

License

Unless otherwhise noted the contents of this homepage are governed by a Creative Commins license (CC-BY) that essentially means you may use my content to remix it into your work but name me.

Social

Contact

You can send me an email to tobiasdiekershoff.net or see the imprint for further contacts channels.

Made with

Powered by Pelican. Theme inspired by Bootply using the Sandstone color schema.