From f73c873681a7daf3c9f70e0c216b5b3b76ba40ad Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Wed, 5 Jul 2017 07:58:40 -0500 Subject: [PATCH] Expose some internal data to all hooks * Command run by yadm * Full commandline arguments * Repo directory * Worktree * Exit status (for post hooks) --- yadm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/yadm b/yadm index 57eb5bb..a547142 100755 --- a/yadm +++ b/yadm @@ -31,6 +31,7 @@ YADM_ARCHIVE="files.gpg" YADM_BOOTSTRAP="bootstrap" HOOK_COMMAND="" +FULL_COMMAND="" GPG_PROGRAM="gpg" GIT_PROGRAM="git" @@ -55,6 +56,9 @@ function main() { require_git + #; capture full command, for passing to hooks + FULL_COMMAND="$*" + #; create the YADM_DIR if it doesn't exist yet [ -d "$YADM_DIR" ] || mkdir -p "$YADM_DIR" @@ -861,7 +865,7 @@ function error_out() { function exit_with_hook() { - invoke_hook "post" + invoke_hook "post" "$1" exit "$1" } @@ -869,10 +873,24 @@ function exit_with_hook() { function invoke_hook() { mode="$1" + exit_status="$2" hook_command="$YADM_DIR/hooks/${mode}_$HOOK_COMMAND" if [ -x "$hook_command" ] ; then debug "Invoking hook: $hook_command" + + #; expose some internal data to all hooks + YADM_HOOK_COMMAND=$HOOK_COMMAND + YADM_HOOK_EXIT=$exit_status + YADM_HOOK_FULL_COMMAND=$FULL_COMMAND + YADM_HOOK_REPO=$YADM_REPO + YADM_HOOK_WORK=$YADM_WORK + export YADM_HOOK_COMMAND + export YADM_HOOK_EXIT + export YADM_HOOK_FULL_COMMAND + export YADM_HOOK_REPO + export YADM_HOOK_WORK + "$hook_command" fi