From 91c7ed9f4d6bb4afac90b47462627373821d4ff2 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Thu, 9 Sep 2021 09:28:37 +0200 Subject: [PATCH] pre-commit hook to disallow commit with SCSS file but without CSS file --- .make/git-hooks/README.md | 13 +++++++++ .make/git-hooks/install.php | 26 ++++++++++++++++++ .make/git-hooks/pre-commit.php | 49 ++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 .make/git-hooks/README.md create mode 100644 .make/git-hooks/install.php create mode 100644 .make/git-hooks/pre-commit.php diff --git a/.make/git-hooks/README.md b/.make/git-hooks/README.md new file mode 100644 index 000000000..3e14d1ded --- /dev/null +++ b/.make/git-hooks/README.md @@ -0,0 +1,13 @@ +# Git hooks for iTop + +## ❓ Goal + +Those [git hooks](https://git-scm.com/docs/githooks) aims to ease developing on [iTop](https://github.com/Combodo/iTop). + +## ☑ Available hooks + +* pre-commit : rejects commit if you have at least one SCSS file staged, and no CSS file + +## ⚙ Install + +Just run install.php ! diff --git a/.make/git-hooks/install.php b/.make/git-hooks/install.php new file mode 100644 index 000000000..858a27827 --- /dev/null +++ b/.make/git-hooks/install.php @@ -0,0 +1,26 @@ + OK to commit !\n"; +exit(0); + + + +function GetFilesWithExtension($sExtension, $aFiles) { + return array_filter( + $aFiles, + function($item) use ($sExtension) { + return (endsWith($item, '.'.$sExtension)); + } + ); +} + +function endsWith( $haystack, $needle ) { + $length = strlen( $needle ); + if( !$length ) { + return true; + } + return substr( $haystack, -$length ) === $needle; +} + +function exitWithMessage($sMessage, $iCode) { + echo $sMessage; + exit($iCode); +} \ No newline at end of file