Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

### Template

- New pre-commit hooks (large files, merge conflicts) in pipeline template ([#3935](https://github.com/nf-core/tools/pull/3935))

### Linting

### Modules
Expand Down
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."
status=1
break
fi
file_dir=$(dirname "$file_dir")
done
done

exit "$status"
16 changes: 16 additions & 0 deletions nf_core/pipeline-template/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,19 @@ repos:
subworkflows/nf-core/.*|
.*\.snap$
)$
- id: check-added-large-files
args: [--maxkb=5000]
exclude: |
(?x)^(
.*ro-crate-metadata.json$|
.*\.snap$|
lib/nfcore_external_java_deps.jar$|
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
1 change: 1 addition & 0 deletions nf_core/pipelines/create/template_features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ code_quality:
- ".prettierignore"
- ".prettierrc.yml"
- ".github/workflows/fix-linting.yml"
- ".hooks/block_pipeline_outdir.sh"
short_description: "Use code linters"
description: "The pipeline will include code linters and CI tests to lint your code: pre-commit, editor-config and prettier."
help_text: |
Expand Down