0 votes
in Git by
How should I configure a Git repository for running code sanity checking tools?

1 Answer

0 votes
by

Sanity checking helps in determining the possibility and feasibility of continuous testing. A sanity test is possible through a simple script that relates to the pre-commit hook of the concerned repository. The script also helps in running other tools such as linters and execute sanity checks for changes committed to the repository. Here is an example.

#!/bin/sh

files=$(git diff –cached –name-only –diff-filter=ACM | grep ‘.go$’)

if [ -z files ]; then

exit 0

fi

unfmtd=$(gofmt -l $files)

if [ -z unfmtd ]; then

exit 0

fi

echo “Some .go files are not fmt’d”

exit 1

The above-mentioned script evaluates the need for passing any .go file through the standard Go source code formatting tool. Exiting with a non-zero value helps the script prevent the application of the commit to the repository.

Related questions

0 votes
asked Aug 24, 2023 in Git by JackTerrance
0 votes
asked Aug 24, 2023 in Git by JackTerrance
...