You could use PROMPT_COMMAND, the code specified in PROMPT_COMMAND is executed before bash draws the prompt.
# Call function 'foo'
PROMPT_COMMAND=foo
# The function
foo() {
if [[ $PWD == "$HOME/repository/foo" ]]; then
set_foo_env.sh
fi
}
Note, PROMPT_COMMAND is bash specific, and this is not a efficient way because the function foo will be called every time bash draws the prompt.