Installs pre-commit hooks for OCaml projects that run dune fmt automatically
at main 57 lines 1.6 kB view raw
1Test precommit init command 2 3Setup: create a minimal OCaml project with git 4 $ mkdir test-project 5 $ cd test-project 6 $ git init -q 7 $ echo '(lang dune 3.0)' > dune-project 8 9Test dry-run mode shows what would be created 10 $ precommit init --dry-run 11 Would create $TESTCASE_ROOT/test-project/.git/hooks/ 12 Would create $TESTCASE_ROOT/test-project/.git/hooks/pre-commit 13 Would chmod +x $TESTCASE_ROOT/test-project/.git/hooks/pre-commit 14 Would create $TESTCASE_ROOT/test-project/.git/hooks/commit-msg 15 Would chmod +x $TESTCASE_ROOT/test-project/.git/hooks/commit-msg 16 Would create ./.ocamlformat 17 Would initialise . 18 Processed 1 directory 19 20Test actual init creates the hooks 21 $ precommit init 22 Initialised . 23 Processed 1 directory 24 25Verify hooks exist and are executable 26 $ test -x .git/hooks/pre-commit && echo "pre-commit is executable" 27 pre-commit is executable 28 $ test -x .git/hooks/commit-msg && echo "commit-msg is executable" 29 commit-msg is executable 30 31Verify pre-commit hook content 32 $ head -2 .git/hooks/pre-commit 33 #!/bin/sh 34 # Auto-format OCaml files with dune before commit 35 36Verify commit-msg hook content 37 $ head -2 .git/hooks/commit-msg 38 #!/bin/sh 39 # Check commit message for emojis and remove AI attribution lines 40 41Test error when not in a git repo 42 $ cd /tmp 43 $ mkdir no-git-$$ 44 $ cd no-git-$$ 45 $ echo '(lang dune 3.0)' > dune-project 46 $ precommit init 47 No git repositories found 48 [1] 49 50Test error when not in an OCaml project 51 $ cd /tmp 52 $ mkdir no-dune-$$ 53 $ cd no-dune-$$ 54 $ git init -q 55 $ precommit init 56 No OCaml projects found (use --force to install anyway) 57 [1]