Dev setup: correct the hook claim, ship an opt-in committed hook
The naming check was documented as an auto-running pre-commit hook, but .git/hooks is never cloned and no installer existed - a fresh clone had nothing, and the real enforcement is CI. Say that plainly. Ship .githooks/pre-commit (LF-pinned) so a dev who wants the local check can opt in with 'git config core.hooksPath .githooks'; CI stays the backstop that fails the build on a bad name.
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -3,3 +3,4 @@
|
|||||||
# Shell scripts must stay LF so Git Bash on Windows can run them
|
# Shell scripts must stay LF so Git Bash on Windows can run them
|
||||||
*.sh text eol=lf
|
*.sh text eol=lf
|
||||||
scripts/check-naming-and-style.sh text eol=lf
|
scripts/check-naming-and-style.sh text eol=lf
|
||||||
|
.githooks/pre-commit text eol=lf
|
||||||
|
|||||||
5
.githooks/pre-commit
Executable file
5
.githooks/pre-commit
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Committed pre-commit hook. Activate per clone with:
|
||||||
|
# git config core.hooksPath .githooks
|
||||||
|
# Runs the naming/style gate; blocks the commit on failure.
|
||||||
|
exec bash "$(git rev-parse --show-toplevel)/scripts/check-naming-and-style.sh"
|
||||||
@@ -32,14 +32,14 @@ sane, then use manual for day-to-day work.
|
|||||||
|
|
||||||
## 1. Get the code
|
## 1. Get the code
|
||||||
|
|
||||||
```bash
|
```powershell
|
||||||
git clone https://github.com/ge-aero/shopdb-flask.git
|
git clone https://github.com/ge-aero/shopdb-flask.git
|
||||||
cd shopdb-flask
|
cd shopdb-flask
|
||||||
```
|
```
|
||||||
|
|
||||||
Never work on `main`. Branch for your change:
|
Never work on `main`. Branch for your change:
|
||||||
|
|
||||||
```bash
|
```powershell
|
||||||
git checkout -b feat/<short-description>
|
git checkout -b feat/<short-description>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -47,8 +47,8 @@ git checkout -b feat/<short-description>
|
|||||||
|
|
||||||
## 2a. Fast path - Docker (a working site in one command)
|
## 2a. Fast path - Docker (a working site in one command)
|
||||||
|
|
||||||
```bash
|
```powershell
|
||||||
cp .env.example .env
|
copy .env.example .env
|
||||||
# Edit .env: set SECRET_KEY, JWT_SECRET_KEY, and the MYSQL_* passwords.
|
# Edit .env: set SECRET_KEY, JWT_SECRET_KEY, and the MYSQL_* passwords.
|
||||||
# Generate a secret: python -c "import secrets;print(secrets.token_urlsafe(64))"
|
# Generate a secret: python -c "import secrets;print(secrets.token_urlsafe(64))"
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ hot-reloads.
|
|||||||
Either point at an existing MySQL 8, or bring one up with just the db service
|
Either point at an existing MySQL 8, or bring one up with just the db service
|
||||||
from compose:
|
from compose:
|
||||||
|
|
||||||
```bash
|
```powershell
|
||||||
docker compose up -d db # MySQL on 127.0.0.1:3306
|
docker compose up -d db # MySQL on 127.0.0.1:3306
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -130,13 +130,13 @@ foreach ($p in "computers","employees","machines","measuringtools","network",
|
|||||||
Run the backend ON PORT 5001 - the frontend dev server proxies `/api` and
|
Run the backend ON PORT 5001 - the frontend dev server proxies `/api` and
|
||||||
`/static` there (a bare `flask run` uses 5000 and nothing will load):
|
`/static` there (a bare `flask run` uses 5000 and nothing will load):
|
||||||
|
|
||||||
```bash
|
```powershell
|
||||||
flask run --port 5001
|
flask run --port 5001
|
||||||
```
|
```
|
||||||
|
|
||||||
### Frontend (a second terminal)
|
### Frontend (a second terminal)
|
||||||
|
|
||||||
```bash
|
```powershell
|
||||||
cd frontend
|
cd frontend
|
||||||
npm install
|
npm install
|
||||||
npm run dev # http://localhost:5173
|
npm run dev # http://localhost:5173
|
||||||
@@ -173,17 +173,27 @@ tasks call `venv/` and `frontend/node_modules`).
|
|||||||
## 3. The development loop
|
## 3. The development loop
|
||||||
|
|
||||||
1. Make a change. Backend: `flask run` auto-reloads. Frontend: Vite hot-reloads.
|
1. Make a change. Backend: `flask run` auto-reloads. Frontend: Vite hot-reloads.
|
||||||
2. Before committing, run the same three gates CI runs. In VS Code the
|
2. Before committing, run the three gates. Easiest: in VS Code, Command
|
||||||
task **Check: naming + tests + build** runs all three; by hand:
|
Palette > "Tasks: Run Task" > **Check: naming + tests + build**. By hand
|
||||||
|
in PowerShell:
|
||||||
```powershell
|
```powershell
|
||||||
bash scripts/check-naming-and-style.sh # naming hook - needs Git Bash
|
|
||||||
venv\Scripts\python -m pytest tests/ -q # backend
|
venv\Scripts\python -m pytest tests/ -q # backend
|
||||||
cd frontend; npx vitest run; npm run build
|
cd frontend; npx vitest run; npm run build; cd ..
|
||||||
|
bash scripts/check-naming-and-style.sh # naming - runs via Git Bash
|
||||||
```
|
```
|
||||||
The naming check is a bash script; on Windows it runs under Git Bash
|
There is NO auto-installed git hook - you run these yourself (or the
|
||||||
(installed with Git for Windows). The git PRE-COMMIT hook runs it
|
VS Code task). CI runs all three on every push and will fail the build
|
||||||
automatically on every `git commit`, so a bad name is caught even if you
|
if a name is wrong, so nothing bad reaches `main`; running them locally
|
||||||
forget to run it - just make sure Git for Windows is installed.
|
just saves the round trip. The naming check is a shell script, so that
|
||||||
|
one line needs Git Bash (installed with Git for Windows).
|
||||||
|
|
||||||
|
Want it automatic? The repo ships a hook; enable it once per clone:
|
||||||
|
```powershell
|
||||||
|
git config core.hooksPath .githooks
|
||||||
|
```
|
||||||
|
Now every `git commit` runs the naming check first (Git for Windows
|
||||||
|
executes the hook under its bundled bash) and blocks the commit if a name
|
||||||
|
is wrong. Purely local convenience; CI is the real backstop.
|
||||||
3. Commit in small, working steps. Subject: short, present tense, plain
|
3. Commit in small, working steps. Subject: short, present tense, plain
|
||||||
English; body says WHY. Read `CONTRIBUTING.md` before naming anything - the
|
English; body says WHY. Read `CONTRIBUTING.md` before naming anything - the
|
||||||
naming hook will reject snake_case DB columns, banned shorthand, and
|
naming hook will reject snake_case DB columns, banned shorthand, and
|
||||||
@@ -206,7 +216,7 @@ answer key. It touches every hook the framework has.
|
|||||||
|
|
||||||
## 5. Contributing back
|
## 5. Contributing back
|
||||||
|
|
||||||
```bash
|
```powershell
|
||||||
git push -u origin feat/<short-description>
|
git push -u origin feat/<short-description>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user