From ac824f7641a94d4c10ca31d80845fd149fa8426a Mon Sep 17 00:00:00 2001 From: Simx303 <75362577+Simx303@users.noreply.github.com> Date: Mon, 23 Sep 2024 21:04:28 +0300 Subject: [PATCH] Added FILES env variable `FILES` environment variable will be available for scripts by adding `... $FILES ...` to their script. It will list all staged files for commit. --- simple-git-hooks.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/simple-git-hooks.js b/simple-git-hooks.js index c57f8c4..9615c7c 100644 --- a/simple-git-hooks.js +++ b/simple-git-hooks.js @@ -42,12 +42,20 @@ if [ "$SKIP_SIMPLE_GIT_HOOKS" = "1" ]; then exit 0 fi +FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') + if [ -f "$SIMPLE_GIT_HOOKS_RC" ]; then . "$SIMPLE_GIT_HOOKS_RC" fi ` +const APPEND_SCRIPT = +` + +echo "$FILES" | xargs git add +` + /** * Recursively gets the .git folder path from provided directory * @param {string} directory @@ -192,7 +200,7 @@ function _setHook(hook, command, projectRoot=process.cwd()) { return } - const hookCommand = PREPEND_SCRIPT + command + const hookCommand = PREPEND_SCRIPT + command + APPEND_SCRIPT const hookDirectory = gitRoot + '/hooks/' const hookPath = path.normalize(hookDirectory + hook)