Skip to content

Commit 74c11b1

Browse files
Add custom pre-commit hook to check for a pipeline output directory.
1 parent 71ef635 commit 74c11b1

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
# This hook is used to block commits if they include staged files inside a directory
3+
# which also contains a subdirectory called `pipeline_info`. The purpose of this is to
4+
# prevent users from inadvertently committing output from pipeline test runs inside the
5+
# development directory.
6+
7+
set -e
8+
9+
# list staged files
10+
staged_files="$(git diff --cached --name-only)"
11+
12+
status=0
13+
14+
for file in $staged_files; do
15+
file_dir=$(dirname "$file")
16+
17+
# Walk up the directory tree and check if the current directory contains a subdirectory called `pipeline_info`
18+
# or the staged file is itself inside a directory called `pipeline_info`.
19+
while [ "$file_dir" != "." ] && [ "$file_dir" != "/" ]; do
20+
if [ $(basename "$file_dir") == "pipeline_info" ] || [ -d "$file_dir/pipeline_info" ]; then
21+
echo "❌ Commit blocked: Please do not commit output from pipeline test runs to the pipeline code itself."
22+
echo "Use 'git restore --staged <file>...' to remove the output files from the staging area before proceeding."
23+
status=1
24+
break
25+
fi
26+
file_dir=$(dirname "$file_dir")
27+
done
28+
done
29+
30+
exit "$status"

nf_core/pipeline-template/.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ repos:
3535
docs/.*\.(svg|pdf)$
3636
)$
3737
- id: check-merge-conflict
38+
- repo: local
39+
hooks:
40+
- id: block-pipeline-outdir
41+
name: Prevent committing output from pipeline test runs to the pipeline code itself
42+
entry: ./.hooks/block_pipeline_outdir.sh
43+
language: script

0 commit comments

Comments
 (0)