diff --git a/.envrc b/.envrc index e3a70f900..43e35e689 100644 --- a/.envrc +++ b/.envrc @@ -1,29 +1,29 @@ #!/bin/bash -read -p "Do you want to setup git commit hooks? (y/Y to continue): " response -if [[ "$response" =~ ^[yY]$ ]]; then - git config core.hooksPath .git-hooks -else - git config --unset core.hooksPath -fi - -read -p "Do you want to continue with Nix operations? (y/Y to continue): " response +nix-build $PWD/default.nix -A env --out-link .nix-env -if [[ "$response" =~ ^[yY]$ ]]; then - nix-build $PWD/default.nix -A env --out-link .nix-env +PATH_add ".nix-env/bin" - PATH_add ".nix-env/bin" +export LOCALHOST_PYTHON="$PWD/.nix-env/bin/python" - export LOCALHOST_PYTHON="$PWD/.nix-env/bin/python" +# source .profile from `$env`. +# This is only used to set things interpolated by nix. +# All *static* things should live inside .envrc. +[[ -f ".nix-env/.profile" ]] && source_env ".nix-env/.profile" - # source .profile from `$env`. - # This is only used to set things interpolated by nix. - # All *static* things should live inside .envrc. - [[ -f ".nix-env/.profile" ]] && source_env ".nix-env/.profile" +# allow local .envrc overrides +[[ -f .envrc.local ]] && source_env .envrc.local - # allow local .envrc overrides - [[ -f .envrc.local ]] && source_env .envrc.local +if [[ "$NO_GIT_HOOKS" == "TRUE" ]]; then + # setting up .git-hooks for commit message verification + git config core.hooksPath .git-hooks -else - echo "Skipping Nix operations." + echo "" + echo " Git Hooks has been configured in your current environment." + echo " Read more about them here: https://github.com/wireapp/wire-server-deploy?tab=readme-ov-file#optional-git-commit-message-verification" + echo " If you don't want to use it, then set NO_GIT_HOOKS=FALSE in file .envrc.local and re-laod the envionment by running:" + echo " direnv reload" + echo "" +else + git config --unset core.hooksPath fi diff --git a/.git-hooks/commit-msg b/.git-hooks/commit-msg index 342ffa730..11e307f09 100755 --- a/.git-hooks/commit-msg +++ b/.git-hooks/commit-msg @@ -16,6 +16,8 @@ if ! echo "$commit_message" | grep -E "$pattern" | grep -E "$pattern2"; then echo " refactor: wpb-1234 clean up code" echo " test: add unit tests wpb-1234" echo " chore!: WPB-1234 drop support for k8s 1.16 - add a 'BREAKING CHANGE:' statement" - echo "Read more about it here: https://www.conventionalcommits.org/en/v1.0.0/" + echo " Read more about it here: https://www.conventionalcommits.org/en/v1.0.0/" + echo " If you don't want to use it, then set NO_GIT_HOOKS=FALSE in file .envrc.local and re-laod the envionment by running:" + echo " direnv reload" exit 1 fi diff --git a/README.md b/README.md index 169758e7f..cd65bb9a3 100644 --- a/README.md +++ b/README.md @@ -92,9 +92,24 @@ This repository uses a Git commit [hook](./.git-hooks/commit-msg) to enforce the - *chore!: WPB-1234 drop support for k8s 1.16 - add a 'BREAKING CHANGE:' statement* #### Activation/Deactivation: -The commit hook is optional and can be activated or deactivated using the `.envrc` script with direnv: -``` +The commit hook is optional and can be activated using the `.envrc` script with direnv as: +```bash wire-server-deploy$ direnv allow direnv: loading ~/projects/git/wire-server-deploy/.envrc -Do you want to setup git commit hooks? (y/Y to continue): +direnv: ([/usr/bin/direnv export zsh]) is taking a while to execute. Use CTRL-C to give up. +/nix/store/bbh6750da4dmnbizgwzh5q2g5z6njd81-wire-server-deploy +direnv: loading ~/projects/git/wire-server-deploy/.nix-env/.nix-env/.profile + + Git Hooks has been configured in your current environment. + Read more about them here: https://github.com/wireapp/wire-server-deploy?tab=readme-ov-file#optional-git-commit-message-verification + If you don't want to use it, run the following command to unset it + git config --unset core.hooksPath + +direnv: export +LOCALHOST_PYTHON +NIX_PATH ~PATH +``` + +The `.git-hooks` get configured when the whole `.envrc` environment is allowed. Run the following command if hooks for commit message verification aren't required: + +```bash +git config --unset core.hooksPath ``` diff --git a/changelog.d/5-bug-fixes/issue-862-direnv-fix b/changelog.d/5-bug-fixes/issue-862-direnv-fix new file mode 100644 index 000000000..4f1cf2bff --- /dev/null +++ b/changelog.d/5-bug-fixes/issue-862-direnv-fix @@ -0,0 +1 @@ +Fixed: remove read function to operate .envrc and updated the README.md