Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-commit hooks support #6

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-merge-conflict
- repo: https://github.com/jorisroovers/gitlint
rev: v0.17.0
hooks:
- id: gitlint

- repo: local
hooks:
- id: gstreamer
name: gstreamer
entry: hooks/gstreamer.hook
language: script
files: ^gst.*\.(c|h|cpp)$
12 changes: 8 additions & 4 deletions hooks/pre-commit.hook → hooks/gstreamer.hook
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ INDENT_PARAMETERS="--braces-on-if-line \
--leave-preprocessor-space"

echo "--Checking style--"
for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "\.c$"` ; do
for file in "$@" ; do
# nf is the temporary checkout. This makes sure we check against the
# revision in the index (and not the checked out version).
nf=`git checkout-index --temp ${file} | cut -f 1`
Expand All @@ -62,8 +62,12 @@ for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "
# FIXME: Call indent twice as it tends to do line-breaks
# different for every second call.
$INDENT ${INDENT_PARAMETERS} \
$newfile 2>> /dev/null
diff -u -p "${nf}" "${newfile}"
$newfile 2>> /dev/null
$INDENT ${INDENT_PARAMETERS} \
$file 2>> /dev/null
$INDENT ${INDENT_PARAMETERS} \
$file 2>> /dev/null
diff -u -p "${nf}" "${newfile}" >> /dev/null
r=$?
rm "${newfile}"
rm "${nf}"
Expand All @@ -74,7 +78,7 @@ echo "
echo " Please fix before committing. Don't forget to run git add before trying to commit again. "
echo " If the whole file is to be committed, this should work (run from the top-level directory): "
echo " "
echo " gst-indent $file; git add $file; git commit"
echo " git add $file; git commit"
echo " "
echo "================================================================================================="
exit 1
Expand Down
11 changes: 8 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,14 @@ gnome = import('gnome')
# Imports pkgconfig module
pkgconfig = import('pkgconfig')

# Install git hooks
python3 = import('python').find_installation()
run_command(python3, '-c', 'import shutil; shutil.copy("hooks/pre-commit.hook", ".git/hooks/pre-commit")')
# Install pre-commit hooks
developer_mode = get_option('developer-mode')
if developer_mode
pre_commit = find_program('pre-commit', required: true, native: true)
run_command(pre_commit, 'install', check: true)
run_command(pre_commit, 'install', '--hook-type', 'commit-msg', check: true)
endif


# Meson will generate a header file all the entries in the configuration data object
configure_file(output : 'config.h', configuration : cdata)
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Feature options
option('developer-mode', type : 'boolean', value : false, yield : true, description: 'Enable developer mode')
option('tests', type : 'feature', value : 'auto', yield : true, description : 'Build tests')
option('examples', type : 'feature', value : 'auto', yield : true, description : 'Build examples')
option('gtk-doc', type : 'boolean', value : false, description : 'Use gtk-doc to build documentation')
Expand Down