From 1359500e17abcf37125e4c857050be4adad9c6af Mon Sep 17 00:00:00 2001
From: "p.rogalski"
Date: Thu, 7 Dec 2023 17:08:07 +0100
Subject: [PATCH] Add "pdm-sync" pre-commit hook
---
.pre-commit-hooks.yaml | 13 ++++++++++++-
docs/docs/usage/advanced.md | 11 +++++++++++
news/2474.feature.md | 1 +
3 files changed, 24 insertions(+), 1 deletion(-)
create mode 100644 news/2474.feature.md
diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml
index 9ac5555275..8ad289328f 100644
--- a/.pre-commit-hooks.yaml
+++ b/.pre-commit-hooks.yaml
@@ -13,4 +13,15 @@
language: python
language_version: python3
pass_filenames: false
- files: ^pdm.lock$
+ files: ^pdm.lock$
+- id: pdm-sync
+ name: pdm-sync
+ description: sync current working set with pdm.lock
+ entry: pdm sync
+ language: python
+ language_version: python3
+ pass_filenames: false
+ stages:
+ - post-checkout
+ - post-merge
+ always_run: true
diff --git a/docs/docs/usage/advanced.md b/docs/docs/usage/advanced.md
index eb370bf7f9..b3dd0f8230 100644
--- a/docs/docs/usage/advanced.md
+++ b/docs/docs/usage/advanced.md
@@ -244,3 +244,14 @@ This hook wraps the command `pdm lock --check` along with any valid argument. It
hooks:
- id: pdm-lock-check
```
+
+### Sync current working set with `pdm.lock`
+
+This hook wraps the command `pdm sync` along with any valid argument. It can be used as a hook to ensure that your current working set is synced with `pdm.lock` whenever you checkout or merge a branch.
+
+```yaml
+- repo: https://github.com/pdm-project/pdm
+ rev: 2.x.y # a PDM release exposing the hook
+ hooks:
+ - id: pdm-sync
+```
\ No newline at end of file
diff --git a/news/2474.feature.md b/news/2474.feature.md
new file mode 100644
index 0000000000..fa8b0ac0a5
--- /dev/null
+++ b/news/2474.feature.md
@@ -0,0 +1 @@
+Add "pdm sync" pre-commit hook
\ No newline at end of file