Git
Integrate codee format
with git
to format only the changes made to your
Fortran code.
Setup
codee format
ships with a git-codee-format
script, which formats only the
changes you have staged in git
.
Adding Codee's binaries to the system's PATH
will allow git
to recognize
git codee-format
as a valid sub-command. Please refer to the Codee
Installation Guide for platform-specific
instructions.
Usage
Suppose a series of staged changes to your Fortran code:
diff --git a/tst.f90 b/tst.f90
index 000000000000..ffffffffffff 100644
--- a/tst.f90
+++ b/tst.f90
@@ -1,6 +1,7 @@
module points
type :: point
real :: x, y
+ integer::z
Run the git codee-format
command from a terminal inside your Git repository
to format only the staged changes.
After formatting, the changes will appear as new, unstaged modifications:
diff --git a/tst.f90 b/tst.f90
index f3059c04c2e4..d099353ca8fe 100644
--- a/tst.f90
+++ b/tst.f90
@@ -1,7 +1,7 @@
module points
type :: point
real :: x, y
- integer::z
+ integer :: z
end type point
Configure a pre-commit
hook to use Codee Format
Optional tools
pre-commit
package manager installed in your system.
This is not an actual requirement but a simpler and more robust approach to git hooks.
Configuration
1. Codee Format pre-commit
configuration
Create a file named .pre-commit-config.yaml
. The following example
shows you how to configure the pre-commit
hook so it uses codee format
on the new code:
repos:
- repo: local
hooks:
- id: codee-format
name: Codee Format
entry: git codee-format
language: system
types: [file]
files: '\.(f|F|f90|F90|f95|F95)$'
Finally, run pre-commit install
in the root of the repository to set
up the git hook scripts.
pre-commit install
Now the pre-commit
hook is installed at .git/hooks/pre-commit
and it will
run automatically on git commit
.