From 8cbbf6689d9fe2638952b7900d0c491d58cb017a Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Thu, 15 May 2025 16:46:22 +0100 Subject: [PATCH] fix: Use `git lfs install` and fix verify-commits hook (#2129) --- .pre-commit-config.yaml | 32 +++--------------------------- CONTRIBUTING.md | 12 ++++++++++- pre-commit-hooks/lfs/post-checkout | 3 --- pre-commit-hooks/lfs/post-commit | 3 --- pre-commit-hooks/lfs/post-merge | 3 --- pre-commit-hooks/lfs/pre-push | 3 --- pre-commit-hooks/verify-commits.sh | 22 ++++++++++---------- 7 files changed, 24 insertions(+), 54 deletions(-) delete mode 100755 pre-commit-hooks/lfs/post-checkout delete mode 100755 pre-commit-hooks/lfs/post-commit delete mode 100755 pre-commit-hooks/lfs/post-merge delete mode 100755 pre-commit-hooks/lfs/pre-push diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fd6ed708..68f44ba0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ # Common tasks # # - Run on all files: pre-commit run --all-files -# - Register git hooks: pre-commit install --install-hooks +# - Register git hooks: pre-commit install --hook-type pre-commit --hook-type pre-push # # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks @@ -94,33 +94,7 @@ repos: - id: verify-commits name: Verify Commits entry: pre-commit-hooks/verify-commits.sh - types: [text] - language: script - pass_filenames: false - - - repo: local - hooks: - - id: lfs-post-checkout - name: LFS Post Checkout - entry: pre-commit-hooks/lfs/post-checkout - types: [text] - stages: [post-checkout] - language: script - - id: lfs-post-commit - name: LFS Post Commit - entry: pre-commit-hooks/lfs/post-commit - types: [text] - stages: [post-commit] - language: script - - id: lfs-post-merge - name: LFS Post Merge - entry: pre-commit-hooks/lfs/post-merge - types: [text] - stages: [post-merge] - language: script - - id: lfs-pre-push - name: LFS Pre Push - entry: pre-commit-hooks/lfs/pre-push - types: [text] + always_run: true stages: [pre-push] language: script + pass_filenames: false diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ed781906..24cb3f88 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,6 +17,16 @@ To contribute, please: > **Note:** Please read the [Style guide](#style-guide). +### `git lfs` hooks + +Install `git lfs` hooks using the following command: + +```bash +git lfs install +``` + +> **Note:** You need to install Git LFS hooks before installing `pre-commit` hooks. + ### `pre-commit` hooks To ensure code quality and style, we use [`pre-commit`](https://pre-commit.com/). @@ -25,7 +35,7 @@ Run the following command to enable `pre-commit` hooks that help with Clio devel ```bash pip3 install pre-commit -pre-commit install +pre-commit install --hook-type pre-commit --hook-type pre-push ``` `pre-commit` takes care of running each tool in [`.pre-commit-config.yaml`](https://github.com/XRPLF/clio/blob/develop/.pre-commit-config.yaml) in a separate environment. diff --git a/pre-commit-hooks/lfs/post-checkout b/pre-commit-hooks/lfs/post-checkout deleted file mode 100755 index ca7fcb40..00000000 --- a/pre-commit-hooks/lfs/post-checkout +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; } -git lfs post-checkout "$@" diff --git a/pre-commit-hooks/lfs/post-commit b/pre-commit-hooks/lfs/post-commit deleted file mode 100755 index 52b339cb..00000000 --- a/pre-commit-hooks/lfs/post-commit +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; } -git lfs post-commit "$@" diff --git a/pre-commit-hooks/lfs/post-merge b/pre-commit-hooks/lfs/post-merge deleted file mode 100755 index a912e667..00000000 --- a/pre-commit-hooks/lfs/post-merge +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; } -git lfs post-merge "$@" diff --git a/pre-commit-hooks/lfs/pre-push b/pre-commit-hooks/lfs/pre-push deleted file mode 100755 index 0f0089bc..00000000 --- a/pre-commit-hooks/lfs/pre-push +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; } -git lfs pre-push "$@" diff --git a/pre-commit-hooks/verify-commits.sh b/pre-commit-hooks/verify-commits.sh index a224aa90..2ebf170f 100755 --- a/pre-commit-hooks/verify-commits.sh +++ b/pre-commit-hooks/verify-commits.sh @@ -39,16 +39,14 @@ verify_tag_signed() { fi } -while read local_ref local_oid remote_ref remote_oid; do - # Check some things if we're pushing a branch called "release/" - if echo "$remote_ref" | grep ^refs\/heads\/release\/ &> /dev/null ; then - version=$(git tag --points-at HEAD) - echo "Looks like you're trying to push a $version release..." - echo "Making sure you've signed and tagged it." - if verify_commit_signed && verify_tag && verify_tag_signed ; then - : # Ok, I guess you can push - else - exit 1 - fi +# Check some things if we're pushing a branch called "release/" +if echo "$PRE_COMMIT_REMOTE_BRANCH" | grep ^refs\/heads\/release\/ &> /dev/null ; then + version=$(git tag --points-at HEAD) + echo "Looks like you're trying to push a $version release..." + echo "Making sure you've signed and tagged it." + if verify_commit_signed && verify_tag && verify_tag_signed ; then + : # Ok, I guess you can push + else + exit 1 fi -done +fi