diff --git a/test/test_bootstrap.py b/test/test_bootstrap.py index 4865ece5..c1882e5d 100644 --- a/test/test_bootstrap.py +++ b/test/test_bootstrap.py @@ -22,6 +22,7 @@ def test_bootstrap( paths.bootstrap.write( '#!/bin/bash\n' f'echo {expect}\n' + f'[[ $(id -un) = $YADM_USER ]] && echo "user is set"\n' f'exit {code}\n' ) paths.bootstrap.chmod(0o775) @@ -30,6 +31,7 @@ def test_bootstrap( if exists and executable: assert run.err == '' assert expect in run.out + assert 'user is set' in run.out else: assert expect in run.err assert run.out == '' diff --git a/test/test_unit_set_alt_values.py b/test/test_unit_set_alt_values.py index 8eb9c100..3730f34a 100644 --- a/test/test_unit_set_alt_values.py +++ b/test/test_unit_set_alt_values.py @@ -27,7 +27,7 @@ def test_set_alt_values( YADM_TEST=1 source {yadm} && set_operating_system && YADM_DIR={paths.yadm} YADM_DATA={paths.data} configure_paths && - set_alt_values + ALT_VALUES_SET=0 set_alt_values echo "class='$YADM_CLASS'" echo "os='$YADM_OS'" echo "host='$YADM_HOSTNAME'" @@ -69,7 +69,7 @@ def test_distro(runner, yadm): YADM_TEST=1 source {yadm} function config() {{ echo "$1"; }} function query_distro() {{ echo "testdistro"; }} - set_alt_values + ALT_VALUES_SET=0 set_alt_values echo "distro='$YADM_DISTRO'" """ run = runner(command=['bash'], inp=script) diff --git a/yadm b/yadm index f74c5021..78ce653a 100755 --- a/yadm +++ b/yadm @@ -63,6 +63,7 @@ ENCRYPT_INCLUDE_FILES="unparsed" LEGACY_WARNING_ISSUED=0 INVALID_ALT=() +ALT_VALUES_SET="${YADM_TEST:-0}" GPG_OPTS=() OPENSSL_OPTS=() @@ -596,6 +597,9 @@ function remove_stale_links() { function set_alt_values() { + [[ $ALT_VALUES_SET = 1 ]] && return + ALT_VALUES_SET=1 + export YADM_CLASS export YADM_ARCH export YADM_OS @@ -698,6 +702,8 @@ function bootstrap() { # GIT_DIR should not be set for user's bootstrap code unset GIT_DIR + set_alt_values + echo "Executing $YADM_BOOTSTRAP" exec "$YADM_BOOTSTRAP" @@ -1770,6 +1776,8 @@ function invoke_hook() { export -f unix_path export -f mixed_path + set_alt_values + "$hook_command" hook_status=$? diff --git a/yadm.1 b/yadm.1 index 6f4ba6ba..b2610a19 100644 --- a/yadm.1 +++ b/yadm.1 @@ -112,7 +112,9 @@ to "false". .B bootstrap Execute .I $HOME/.config/yadm/bootstrap -if it exists. +if it exists. The variables that are set when processing Jinja or ESH templates +(see the TEMPLATES section) are set in the environment (except for +.IR YADM_SOURCE ). .TP .BI clone " url Clone a remote repository for tracking dotfiles. @@ -876,7 +878,10 @@ will never be run. This allows one to "short-circuit" any operation using a .I pre_ hook. -Hooks have the following environment variables available to them at runtime: +Hooks have the following variables, plus the variables set when processing +Jinja or ESH templates (see the TEMPLATES section), available to them as +environment variables at runtime (except for +.IR YADM_SOURCE ). .TP .B YADM_HOOK_COMMAND The command which triggered the hook