Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add custom pre-commit hook to check for a pipeline output directory.
  • Loading branch information
MatthiasZepper committed Dec 11, 2025
commit 0295768abe7da16262801771dcf9d1e4114262c4
30 changes: 30 additions & 0 deletions nf_core/pipeline-template/.hooks/block_pipeline_outdir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# This hook is used to block commits if they include staged files inside a directory
# which also contains a subdirectory called `pipeline_info`. The purpose of this is to
# prevent users from inadvertently committing output from pipeline test runs inside the
# development directory.

set -e

# list staged files
staged_files="$(git diff --cached --name-only)"

status=0

for file in $staged_files; do
file_dir=$(dirname "$file")

# Walk up the directory tree and check if the current directory contains a subdirectory called `pipeline_info`
# or the staged file is itself inside a directory called `pipeline_info`.
while [ "$file_dir" != "." ] && [ "$file_dir" != "/" ]; do
if [ $(basename "$file_dir") == "pipeline_info" ] || [ -d "$file_dir/pipeline_info" ]; then
echo "❌ Commit blocked: Please do not commit output from pipeline test runs to the pipeline code itself."
echo "Use 'git restore --staged <file>...' to remove the output files from the staging area before proceeding."
Comment on lines +21 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this also print out the offending path?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could change the script to print out $file, yes.

However, I reckon that people may typically have added their whole output folder to the staging area and then it is more effective to remove all relevant files at once instead single files. I would, though, not want to make the call what that top-level folder is.

status=1
break
fi
file_dir=$(dirname "$file_dir")
done
done

exit "$status"
6 changes: 6 additions & 0 deletions nf_core/pipeline-template/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ repos:
docs/.*\.(svg|pdf)$
)$
- id: check-merge-conflict
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main motivation for this PR was evidently the check-added-large-files. Phil just recommended to use the other one as well, because he has it on the MultiQC repo.

If you think that I shouldn't bundle them in one PR to allow separate decisions, I am fine with removing it as well.

- repo: local
hooks:
- id: block-pipeline-outdir
name: Prevent committing output from pipeline test runs to the pipeline code itself
entry: ./.hooks/block_pipeline_outdir.sh
language: script