scripts: Run checks only on staged files
Fixes: https://gitlab.gnome.org/GNOME/fractal/-/issues/935
This commit is contained in:
parent
f5da9ca917
commit
61dedcb7be
2 changed files with 54 additions and 9 deletions
|
@ -11,7 +11,7 @@ res="\e[0m"
|
||||||
echo "-- Pre-commit checks --"
|
echo "-- Pre-commit checks --"
|
||||||
echo "To ignore these checks next time, run: git commit --no-verify"
|
echo "To ignore these checks next time, run: git commit --no-verify"
|
||||||
echo ""
|
echo ""
|
||||||
if scripts/checks.sh; then
|
if scripts/checks.sh --git-staged; then
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "Pre-commit checks result: ${pos}ok${res}"
|
echo -e "Pre-commit checks result: ${pos}ok${res}"
|
||||||
elif [[ $? -eq 2 ]]; then
|
elif [[ $? -eq 2 ]]; then
|
||||||
|
|
|
@ -13,6 +13,7 @@ If a dependency is not found, helps the user to install it.
|
||||||
USAGE: ${0##*/} [OPTIONS]
|
USAGE: ${0##*/} [OPTIONS]
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
|
-s, --git-staged Only check files staged to be committed
|
||||||
-f, --force-install Install missing dependencies without asking
|
-f, --force-install Install missing dependencies without asking
|
||||||
-v, --verbose Use verbose output
|
-v, --verbose Use verbose output
|
||||||
-h, --help Display this help and exit
|
-h, --help Display this help and exit
|
||||||
|
@ -40,6 +41,7 @@ ok="${pos}ok${res}"
|
||||||
fail="${neg}fail${res}"
|
fail="${neg}fail${res}"
|
||||||
|
|
||||||
# Initialize variables
|
# Initialize variables
|
||||||
|
git_staged=0
|
||||||
force_install=0
|
force_install=0
|
||||||
verbose=0
|
verbose=0
|
||||||
|
|
||||||
|
@ -203,6 +205,25 @@ run_rustfmt() {
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [[ $git_staged -eq 1 ]]; then
|
||||||
|
staged_files=`git diff --name-only --cached | grep '.rs$'`
|
||||||
|
result=0
|
||||||
|
for file in ${staged_files[@]}; do
|
||||||
|
|
||||||
|
if ! rustfmt --unstable-features --skip-children --check $file; then
|
||||||
|
result=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ $result -eq 1 ]]; then
|
||||||
|
echo -e " Checking code style result: $fail"
|
||||||
|
echo "Please fix the above issues, either manually or by running: cargo fmt --all"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo -e " Checking code style result: $ok"
|
||||||
|
fi
|
||||||
|
else
|
||||||
if ! cargo +nightly fmt --all -- --check; then
|
if ! cargo +nightly fmt --all -- --check; then
|
||||||
echo -e " Checking code style result: $fail"
|
echo -e " Checking code style result: $fail"
|
||||||
echo "Please fix the above issues, either manually or by running: cargo fmt --all"
|
echo "Please fix the above issues, either manually or by running: cargo fmt --all"
|
||||||
|
@ -210,6 +231,7 @@ run_rustfmt() {
|
||||||
else
|
else
|
||||||
echo -e " Checking code style result: $ok"
|
echo -e " Checking code style result: $ok"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -263,7 +285,9 @@ run_typos() {
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! typos --color always; then
|
staged_files=`git diff --name-only --cached`
|
||||||
|
|
||||||
|
if ! typos --color always ${staged_files}; then
|
||||||
echo -e " Checking spelling mistakes result: $fail"
|
echo -e " Checking spelling mistakes result: $fail"
|
||||||
echo "Please fix the above issues, either manually or by running: typos -w"
|
echo "Please fix the above issues, either manually or by running: typos -w"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -444,6 +468,9 @@ check_resources() {
|
||||||
|
|
||||||
# Check arguments
|
# Check arguments
|
||||||
while [[ "$1" ]]; do case $1 in
|
while [[ "$1" ]]; do case $1 in
|
||||||
|
-s | --git-staged )
|
||||||
|
git_staged=1
|
||||||
|
;;
|
||||||
-f | --force-install )
|
-f | --force-install )
|
||||||
force_install=1
|
force_install=1
|
||||||
;;
|
;;
|
||||||
|
@ -459,6 +486,17 @@ while [[ "$1" ]]; do case $1 in
|
||||||
exit 1
|
exit 1
|
||||||
esac; shift; done
|
esac; shift; done
|
||||||
|
|
||||||
|
if [[ $git_staged -eq 1 ]]; then
|
||||||
|
staged_files=`git diff --name-only --cached`
|
||||||
|
if [[ -z $staged_files ]]; then
|
||||||
|
echo -e "$Failed to check files because none where staged"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
staged_files=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Run
|
# Run
|
||||||
check_cargo
|
check_cargo
|
||||||
echo ""
|
echo ""
|
||||||
|
@ -468,5 +506,12 @@ run_typos
|
||||||
echo ""
|
echo ""
|
||||||
check_potfiles
|
check_potfiles
|
||||||
echo ""
|
echo ""
|
||||||
|
if [[ $git_staged -eq 1 ]]; then
|
||||||
|
staged_files=`git diff --name-only --cached | grep data/resources/resources.gresource.xml`
|
||||||
|
if [[ -z $staged_files ]]; then
|
||||||
check_resources
|
check_resources
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
check_resources
|
||||||
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
|
|
Loading…
Reference in a new issue