Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions .envrc
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion .git-hooks/commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: it's not really true, since the next direnv run will activate the hooks again.

suggestion: If you want people to be able to opt out of git hooks altogether, you could invent something like a NO_GIT_HOOKS env var that one could put into .envrc.local (which is evaluated prior to setting up the hooks).

Bear in mind I don't really understand your workflow and why being able to opt out of githooks is such a big deal - but in case validation breaks, people can always use --no-verify when committing.
Personally, I'm always happy if projects provide validation hooks, so I'd not even make a fuzz about disabling it 😅


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
```
1 change: 1 addition & 0 deletions changelog.d/5-bug-fixes/issue-862-direnv-fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed: remove read function to operate .envrc and updated the README.md
Loading