diff --git a/.pre-commit b/.pre-commit new file mode 100644 index 000000000..551a1d9e3 --- /dev/null +++ b/.pre-commit @@ -0,0 +1,13 @@ +#!/bin/bash + +# An example pre-commit file for nextSIM-DG development + +for FILE in $(git diff --cached --name-only | grep -iE '\.(cpp|cc|h|hpp)$'); do + # Apply clang-format for linting + clang-format -i ${FILE} --verbose + # Update date stamp to today's date + LINE=$(grep '@date' ${FILE}) + let SPACES=$(echo "${LINE}" | tr -cd ' \t' | wc -c)-4 + NEWLINE=$(printf "%s%$((SPACES))s%s\n" " @date" " " "$(date '+%d %b %Y')") + sed -i~ "s/${LINE}/${NEWLINE}/" ${FILE} +done diff --git a/README.md b/README.md index 06bfdfbd0..669e75537 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ For neXtSIM_DG we use clang-format and the [Webkit style](https://webkit.org/cod - Names and values of physical constants reside in src/include/constants.hpp - Runtime modifiable model parameters are set in src/options.cpp and can be set using option files. -A [dedicated clang format file](https://github.com/nextsimdg/nextsimdg/blob/issue9_clang_format/src/.clang-format) has been designed for the code. You may run it loccaly and manually with the command ```clang-format -i $yourfile``` or have a plugin with your favorite code editor or implement a git pre-commit hook locally by putting this pre-commit file in your .git/hooks/. This clang formatting will also be run each time a pull request is done as part of the continuous integration. +A [dedicated clang format file](https://github.com/nextsimhub/nextsimdg/blob/main/.clang-format) has been designed for the code. You may run it locally and manually with the command ```clang-format -i $yourfile``` or have a plugin with your favorite code editor or implement a git pre-commit hook locally by putting this pre-commit file in your .git/hooks/. An example pre-commit file can be found at [.pre-commit](https://github.com/nextsimhub/nextsimdg/blob/658_pre-commit-date/.pre-commit). This clang formatting will also be run each time a pull request is done as part of the continuous integration. ## Commenting conventions for a nice automatic documentation @@ -47,6 +47,7 @@ Example : */ ``` +Note that the example [pre-commit](https://github.com/nextsimhub/nextsimdg/blob/658_pre-commit-date/.pre-commit) file mentioned above will also automatically update this if moved to `.git/hooks/pre-commit`. We ask every coders to follow the following commenting conventions for comments providing the automatic documentation: - documentation blocks must appear before the component it describes, with the same indentation (classes and functions),