Skip to content

Commit 398a94e

Browse files
authored
Issues 862 direnv fix (#877)
* issue-862: remove read to operate in .envrc * issue-862: update readme.md and commit-msg to reflect new envrc behaviour * issue-862: add changelog.d for direnv behaviour * fix: change git-hook implementation based on envs in .envrc.local file
1 parent 94cb04d commit 398a94e

File tree

4 files changed

+42
-24
lines changed

4 files changed

+42
-24
lines changed

.envrc

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
#!/bin/bash
22

3-
read -p "Do you want to setup git commit hooks? (y/Y to continue): " response
4-
if [[ "$response" =~ ^[yY]$ ]]; then
5-
git config core.hooksPath .git-hooks
6-
else
7-
git config --unset core.hooksPath
8-
fi
9-
10-
read -p "Do you want to continue with Nix operations? (y/Y to continue): " response
3+
nix-build $PWD/default.nix -A env --out-link .nix-env
114

12-
if [[ "$response" =~ ^[yY]$ ]]; then
13-
nix-build $PWD/default.nix -A env --out-link .nix-env
5+
PATH_add ".nix-env/bin"
146

15-
PATH_add ".nix-env/bin"
7+
export LOCALHOST_PYTHON="$PWD/.nix-env/bin/python"
168

17-
export LOCALHOST_PYTHON="$PWD/.nix-env/bin/python"
9+
# source .profile from `$env`.
10+
# This is only used to set things interpolated by nix.
11+
# All *static* things should live inside .envrc.
12+
[[ -f ".nix-env/.profile" ]] && source_env ".nix-env/.profile"
1813

19-
# source .profile from `$env`.
20-
# This is only used to set things interpolated by nix.
21-
# All *static* things should live inside .envrc.
22-
[[ -f ".nix-env/.profile" ]] && source_env ".nix-env/.profile"
14+
# allow local .envrc overrides
15+
[[ -f .envrc.local ]] && source_env .envrc.local
2316

24-
# allow local .envrc overrides
25-
[[ -f .envrc.local ]] && source_env .envrc.local
17+
if [[ "$NO_GIT_HOOKS" == "TRUE" ]]; then
18+
# setting up .git-hooks for commit message verification
19+
git config core.hooksPath .git-hooks
2620

27-
else
28-
echo "Skipping Nix operations."
21+
echo ""
22+
echo " Git Hooks has been configured in your current environment."
23+
echo " Read more about them here: https://github.com/wireapp/wire-server-deploy?tab=readme-ov-file#optional-git-commit-message-verification"
24+
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:"
25+
echo " direnv reload"
26+
echo ""
27+
else
28+
git config --unset core.hooksPath
2929
fi

.git-hooks/commit-msg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ if ! echo "$commit_message" | grep -E "$pattern" | grep -E "$pattern2"; then
1616
echo " refactor: wpb-1234 clean up code"
1717
echo " test: add unit tests wpb-1234"
1818
echo " chore!: WPB-1234 drop support for k8s 1.16 - add a 'BREAKING CHANGE:' statement"
19-
echo "Read more about it here: https://www.conventionalcommits.org/en/v1.0.0/"
19+
echo " Read more about it here: https://www.conventionalcommits.org/en/v1.0.0/"
20+
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:"
21+
echo " direnv reload"
2022
exit 1
2123
fi

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,24 @@ This repository uses a Git commit [hook](./.git-hooks/commit-msg) to enforce the
9292
- *chore!: WPB-1234 drop support for k8s 1.16 - add a 'BREAKING CHANGE:' statement*
9393

9494
#### Activation/Deactivation:
95-
The commit hook is optional and can be activated or deactivated using the `.envrc` script with direnv:
96-
```
95+
The commit hook is optional and can be activated using the `.envrc` script with direnv as:
96+
```bash
9797
wire-server-deploy$ direnv allow
9898
direnv: loading ~/projects/git/wire-server-deploy/.envrc
99-
Do you want to setup git commit hooks? (y/Y to continue):
99+
direnv: ([/usr/bin/direnv export zsh]) is taking a while to execute. Use CTRL-C to give up.
100+
/nix/store/bbh6750da4dmnbizgwzh5q2g5z6njd81-wire-server-deploy
101+
direnv: loading ~/projects/git/wire-server-deploy/.nix-env/.nix-env/.profile
102+
103+
Git Hooks has been configured in your current environment.
104+
Read more about them here: https://github.com/wireapp/wire-server-deploy?tab=readme-ov-file#optional-git-commit-message-verification
105+
If you don't want to use it, run the following command to unset it
106+
git config --unset core.hooksPath
107+
108+
direnv: export +LOCALHOST_PYTHON +NIX_PATH ~PATH
109+
```
110+
111+
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:
112+
113+
```bash
114+
git config --unset core.hooksPath
100115
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed: remove read function to operate .envrc and updated the README.md

0 commit comments

Comments
 (0)