Skip to content

Commit

Permalink
Add pre-commit for automatically updating date stamps (#660)
Browse files Browse the repository at this point in the history
# Add pre-commit for automatically updating date stamps

Closes #658.

Works for me but worth please check this works for you too.
  • Loading branch information
jwallwork23 authored Aug 29, 2024
2 parents a3a2fc3 + 04ec9fc commit a1761e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .pre-commit
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down

0 comments on commit a1761e1

Please # to comment.