From 28920df8958542d3f491e910694457eac58e1522 Mon Sep 17 00:00:00 2001 From: Veaceslav Medvedev Date: Mon, 4 Mar 2019 23:24:33 +0100 Subject: [PATCH 1/4] Update CHANGELOG --- CHANGELOG.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b8de10..34dc2ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,15 +16,19 @@ Security - in case of vulnerabilities. ## [Unreleased] ### Added -- Added hook `disallow-commits` -- Added hook `conventional-commit` -- Added hook `php-cs-fixer` +- Added hook `disallow-commits`. +- Added hook `conventional-commit`. +- Added hook `php-cs-fixer`. - Added help to all hooks, available on running hook with argument `-h` or `--help`. +## Changed +- Allowed multiple commands per file patterns in the `files-watcher`. + + ## [1.1.0] 2019-03-01 ### Added -- Added hook `motivation` -- Added hook `files-watcher` +- Added hook `motivation`. +- Added hook `files-watcher`. ## [1.0.0] 2019-03-01 Initial release. From d8b6f0961e9a1d2bc6eceaaac6fbfe4a10dfeee2 Mon Sep 17 00:00:00 2001 From: Veaceslav Medvedev Date: Mon, 4 Mar 2019 23:24:50 +0100 Subject: [PATCH 2/4] Bump version of file-watcher hook --- files-watcher/files-watcher | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files-watcher/files-watcher b/files-watcher/files-watcher index c8026ab..a66bbe3 100755 --- a/files-watcher/files-watcher +++ b/files-watcher/files-watcher @@ -35,7 +35,7 @@ FCS='\033[0;37m' # Light gray (silver) NC='\033[0m' CMD="files-watcher" -VERSION="1.0.0" +VERSION="1.1.0" HOME="https://github.com/slavcodev/git-hooks-scripts" ABOUT="${FCG}Files watcher${NC} version ${FCY}$VERSION${NC}" HELP="$ABOUT From 93a4be8d2e0210befa4b4d5561dae3662d88e603 Mon Sep 17 00:00:00 2001 From: Veaceslav Medvedev Date: Tue, 5 Mar 2019 00:48:35 +0100 Subject: [PATCH 3/4] Filter only unique files pattern --- files-watcher/files-watcher | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files-watcher/files-watcher b/files-watcher/files-watcher index a66bbe3..15e88ca 100755 --- a/files-watcher/files-watcher +++ b/files-watcher/files-watcher @@ -100,7 +100,7 @@ main() { fi watch_tasks_config_pattern=files-watcher\..\*\.command - watch_tasks=$(git config --name-only --get-regexp ${watch_tasks_config_pattern}) + watch_tasks=$(git config --name-only --get-regexp ${watch_tasks_config_pattern} | sort -u) if [[ -z ${watch_tasks} ]]; then exit From 1277883123733bded0f78bd46346ee0005a809d5 Mon Sep 17 00:00:00 2001 From: Veaceslav Medvedev Date: Tue, 5 Mar 2019 00:49:43 +0100 Subject: [PATCH 4/4] Implement running multiple commands per files pattern --- files-watcher/files-watcher | 45 +++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/files-watcher/files-watcher b/files-watcher/files-watcher index 15e88ca..0de503d 100755 --- a/files-watcher/files-watcher +++ b/files-watcher/files-watcher @@ -50,6 +50,7 @@ ${FCS}~~~ mode = \"auto\" [${CMD} \"composer\.(json|lock)$\"] + command = \"composer self-update\" command = \"composer install -n\" [${CMD} \".php$\"] @@ -122,7 +123,6 @@ main() { changed_files=$(git diff HEAD@\{1\} --name-only --diff-filter=ACMRTUXB | grep -iE ${pattern}) - command=$(git config --type path --get ${task}) mode=$(git config --default ${default_mode} --get ${task%.*}.mode) if [[ -n ${changed_files} ]]; then @@ -132,23 +132,34 @@ main() { echo "- ${FCS}${file}${NC}" done - case "${mode}" in - "auto" ) - command ${command} - ;; - "prompt" ) - if prompt "Do you like to run '${command}'?"; then - command ${command} - fi - ;; - "confirm" ) - if confirm "Do you like to run '${command}'?"; then + previous_ifs=${IFS} + IFS=' +' + commands="$(git config --type path --get-all ${task})" + + set -f + for command in ${commands} ; do + case "${mode}" in + "auto" ) command ${command} - fi - ;; - * ) - echo "${FCR}Invalid mode option${NC}" - esac + ;; + "prompt" ) + if prompt "Do you like to run '${command}'?"; then + command ${command} + fi + ;; + "confirm" ) + if confirm "Do you like to run '${command}'?"; then + command ${command} + fi + ;; + * ) + echo "${FCR}Invalid mode option${NC}" + esac + done + set +f + + IFS=${previous_ifs} fi done