* [pbs-devel] [RFC proxmox-backup] git-hooks: pre-commit runs cargo fmt --check
@ 2024-01-12 14:30 Stefan Lendl
2024-01-12 14:45 ` Stefan Lendl
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Lendl @ 2024-01-12 14:30 UTC (permalink / raw)
To: pbs-devel
* add a pre-commit hook that declines commiting if cargo fmt would make
formatting changes.
* `make install-git-hook` installs the hook
* `make build` installs the hook
* `make uninstall-git-hook` removes the hook
* `make lint` runs cargo fmt --check in addition to cargo clippy
Signed-off-by: Stefan Lendl <s.lendl@proxmox.com>
---
Makefile | 9 ++++++++-
git-hooks/pre-commit | 13 +++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
create mode 100755 git-hooks/pre-commit
diff --git a/Makefile b/Makefile
index 0317dd5e..fc866872 100644
--- a/Makefile
+++ b/Makefile
@@ -86,7 +86,7 @@ doc:
# always re-create this dir
.PHONY: build
-build:
+build: install-git-hooks
rm -rf build
mkdir build
git rev-parse HEAD > build/.repoid
@@ -188,6 +188,7 @@ $(COMPILED_BINS) $(COMPILEDIR)/dump-catalog-shell-cli $(COMPILEDIR)/docgen: .do-
.PHONY: lint
lint:
+ cargo fmt --all -- --check
cargo clippy -- -A clippy::all -D clippy::correctness
install: $(COMPILED_BINS)
@@ -221,3 +222,9 @@ upload: $(SERVER_DEB) $(CLIENT_DEB) $(RESTORE_DEB) $(DOC_DEB)
| ssh -X repoman@repo.proxmox.com upload --product pbs --dist $(UPLOAD_DIST)
tar cf - $(CLIENT_DEB) $(CLIENT_DBG_DEB) | ssh -X repoman@repo.proxmox.com upload --product "pve,pmg,pbs-client" --dist $(UPLOAD_DIST)
tar cf - $(RESTORE_DEB) $(RESTORE_DBG_DEB) | ssh -X repoman@repo.proxmox.com upload --product "pve" --dist $(UPLOAD_DIST)
+
+install-git-hooks:
+ ln -sn ../../git-hooks/pre-commit .git/hooks/pre-commit > /dev/null 2>&1 || true
+
+uninstall-git-hooks:
+ rm -f .git/hooks/pre-commit
diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit
new file mode 100755
index 00000000..729698ad
--- /dev/null
+++ b/git-hooks/pre-commit
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+
+# Run cargo fmt before a commit to ensure the format style
+
+cargo fmt --all -- --check > /dev/null 2>&1
+res=$?
+
+if [[ $res != 0 ]]; then
+ echo "git pre-commit hook: There are some code style issues, run \`cargo fmt\` first."
+ exit 1
+fi
+
+exit 0
--
2.42.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-12 14:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-12 14:30 [pbs-devel] [RFC proxmox-backup] git-hooks: pre-commit runs cargo fmt --check Stefan Lendl
2024-01-12 14:45 ` Stefan Lendl
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal