From 3b613c1201f1bec8d352e241873dc395817fa4c8 Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Thu, 22 Aug 2024 15:21:56 +0100 Subject: [PATCH 1/5] Update path to clang-format --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 06bfdfbd0..cb1c41923 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 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. ## Commenting conventions for a nice automatic documentation From c4ef8f4d217b57fa3b2ae5cf7b21cac60f40a8ab Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Thu, 22 Aug 2024 15:29:26 +0100 Subject: [PATCH 2/5] Add pre-commit file --- .pre-commit | 10 ++++++++++ README.md | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .pre-commit diff --git a/.pre-commit b/.pre-commit new file mode 100644 index 000000000..9619d4ed6 --- /dev/null +++ b/.pre-commit @@ -0,0 +1,10 @@ +#!/usr/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 + sed -i "s/$(grep '\* @date' ${FILE})/ @date $(date '+%d %b %Y')/" ${FILE} +done diff --git a/README.md b/README.md index cb1c41923..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/nextsimhub/nextsimdg/blob/main/.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), From 4f7087f845ffb9faf4b6b47ad726f5840c4d0773 Mon Sep 17 00:00:00 2001 From: Joe Wallwork <22053413+jwallwork23@users.noreply.github.com> Date: Tue, 27 Aug 2024 07:30:44 +0100 Subject: [PATCH 3/5] Use /bin/bash rather than /usr/bin/bash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Einar Örn Ólason --- .pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit b/.pre-commit index 9619d4ed6..1a6cc19c4 100644 --- a/.pre-commit +++ b/.pre-commit @@ -1,4 +1,4 @@ -#!/usr/bin/bash +#!/bin/bash # An example pre-commit file for nextSIM-DG development From 273c3a5b4fbc5b0d7272e2ef92b468e3911c87c3 Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Wed, 28 Aug 2024 09:18:07 +0100 Subject: [PATCH 4/5] Account for spaces in date stamp update --- .pre-commit | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.pre-commit b/.pre-commit index 1a6cc19c4..fbc04696b 100644 --- a/.pre-commit +++ b/.pre-commit @@ -6,5 +6,8 @@ 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 - sed -i "s/$(grep '\* @date' ${FILE})/ @date $(date '+%d %b %Y')/" ${FILE} + 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 From 04ec9fc8d4752ab771433fdc40d7f0d3378caea4 Mon Sep 17 00:00:00 2001 From: Joe Wallwork <22053413+jwallwork23@users.noreply.github.com> Date: Thu, 29 Aug 2024 10:51:31 +0100 Subject: [PATCH 5/5] Use sed's backup option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Einar Örn Ólason --- .pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit b/.pre-commit index fbc04696b..551a1d9e3 100644 --- a/.pre-commit +++ b/.pre-commit @@ -9,5 +9,5 @@ for FILE in $(git diff --cached --name-only | grep -iE '\.(cpp|cc|h|hpp)$'); do 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} + sed -i~ "s/${LINE}/${NEWLINE}/" ${FILE} done