From b187303a1769b3dcc49cd51158f85d03dda545e8 Mon Sep 17 00:00:00 2001 From: Emma Ai Date: Mon, 3 Mar 2025 05:47:05 +0000 Subject: [PATCH 1/4] add pre-commit hook to avoid duplidate ipynb --- .githooks/check_duplicate_ipynb.sh | 29 +++++++++++++++++++++++++++++ .pre-commit-config.yaml | 9 +++++++++ 2 files changed, 38 insertions(+) create mode 100755 .githooks/check_duplicate_ipynb.sh create mode 100644 .pre-commit-config.yaml diff --git a/.githooks/check_duplicate_ipynb.sh b/.githooks/check_duplicate_ipynb.sh new file mode 100755 index 000000000..b7190475a --- /dev/null +++ b/.githooks/check_duplicate_ipynb.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +echo "Checking for duplicate .ipynb filenames in the incoming push..." + +# Get the list of changed files in the push +while read oldrev newrev refname; do + # Get all added/modified .ipynb files + files=$(git diff --name-only --diff-filter=A "$oldrev" "$newrev" | grep '\.ipynb$' || true) + + if [[ -z "$files" ]]; then + continue # No new .ipynb files, skip checking + fi + + # Extract just the filenames (ignore paths) + filenames=$(basename -a $files) + + # Check for duplicates + duplicates=$(echo "$filenames" | sort | uniq -d) + + if [[ -n "$duplicates" ]]; then + echo "Duplicate .ipynb filenames detected in the push:" + echo "$duplicates" + echo "Push rejected! Ensure unique .ipynb filenames." + exit 1 # Reject the push + fi +done + +exit 0 # Allow push if no duplicates + diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..d96b44051 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,9 @@ +repos: + - repo: local + hooks: + - id: check-duplicate-ipynb + name: Check for duplicate .ipynb filenames + entry: bash .githooks/check_duplicate_ipynb.sh + language: system + pass_filenames: false + stages: [pre-commit] From 83170c36cb98e1ea59f8186e579f78de4953f3e8 Mon Sep 17 00:00:00 2001 From: Emma Ai Date: Mon, 3 Mar 2025 05:48:12 +0000 Subject: [PATCH 2/4] add test1 --- How_to_guides/test1.ipynb | 0 test1.ipynb | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 How_to_guides/test1.ipynb create mode 100644 test1.ipynb diff --git a/How_to_guides/test1.ipynb b/How_to_guides/test1.ipynb new file mode 100644 index 000000000..e69de29bb diff --git a/test1.ipynb b/test1.ipynb new file mode 100644 index 000000000..e69de29bb From 46e4df10f8afb5a5df8db1136caaf774acaebb56 Mon Sep 17 00:00:00 2001 From: Emma Ai Date: Mon, 3 Mar 2025 05:53:31 +0000 Subject: [PATCH 3/4] check against local files --- .githooks/check_duplicate_ipynb.sh | 40 +++++++++++++++--------------- How_to_guides/test1.ipynb | 0 test1.ipynb | 0 3 files changed, 20 insertions(+), 20 deletions(-) delete mode 100644 How_to_guides/test1.ipynb delete mode 100644 test1.ipynb diff --git a/.githooks/check_duplicate_ipynb.sh b/.githooks/check_duplicate_ipynb.sh index b7190475a..b39f9115c 100755 --- a/.githooks/check_duplicate_ipynb.sh +++ b/.githooks/check_duplicate_ipynb.sh @@ -1,29 +1,29 @@ #!/bin/bash -echo "Checking for duplicate .ipynb filenames in the incoming push..." +echo "Checking for duplicate .ipynb filenames..." -# Get the list of changed files in the push -while read oldrev newrev refname; do - # Get all added/modified .ipynb files - files=$(git diff --name-only --diff-filter=A "$oldrev" "$newrev" | grep '\.ipynb$' || true) +# Get all existing and staged .ipynb files +all_files=$(git ls-files | grep '\.ipynb$' || true) +staged_files=$(git diff --cached --name-only --diff-filter=A | grep '\.ipynb$' || true) - if [[ -z "$files" ]]; then - continue # No new .ipynb files, skip checking - fi +# Combine them to ensure we check for duplicates globally +combined_files=$(echo -e "$all_files\n$staged_files" | sort -u) - # Extract just the filenames (ignore paths) - filenames=$(basename -a $files) +if [[ -z "$combined_files" ]]; then + exit 0 # No .ipynb files found, allow commit +fi - # Check for duplicates - duplicates=$(echo "$filenames" | sort | uniq -d) +# Extract only filenames (ignore paths) +filenames=$(basename -a $combined_files) - if [[ -n "$duplicates" ]]; then - echo "Duplicate .ipynb filenames detected in the push:" - echo "$duplicates" - echo "Push rejected! Ensure unique .ipynb filenames." - exit 1 # Reject the push - fi -done +# Check for duplicates +duplicates=$(echo "$filenames" | sort | uniq -d) -exit 0 # Allow push if no duplicates +if [[ -n "$duplicates" ]]; then + echo "Duplicate .ipynb filenames detected in repository and staged changes:" + echo "$duplicates" + echo "Commit rejected! Ensure unique .ipynb filenames." + exit 1 # Prevent commit +fi +exit 0 # Allow commit diff --git a/How_to_guides/test1.ipynb b/How_to_guides/test1.ipynb deleted file mode 100644 index e69de29bb..000000000 diff --git a/test1.ipynb b/test1.ipynb deleted file mode 100644 index e69de29bb..000000000 From 59b913ee020937dc227b4785ae44da0bfed3fcde Mon Sep 17 00:00:00 2001 From: Emma Ai Date: Mon, 3 Mar 2025 05:55:10 +0000 Subject: [PATCH 4/4] skip duplicate check in ci --- .pre-commit-config.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d96b44051..0d9452b95 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,6 @@ +ci: + skip: [check-duplicate-ipynb] + repos: - repo: local hooks: