2 changed files with 82 additions and 47 deletions
@ -1,57 +1,37 @@ |
|||||||
#!/bin/sh |
#!/bin/sh |
||||||
# Source: https://gitlab.gnome.org/GNOME/fractal/blob/master/hooks/pre-commit.hook |
# Depends on: scripts/checks.sh |
||||||
|
|
||||||
install_rustfmt() { |
|
||||||
if ! which rustup &> /dev/null; then |
|
||||||
curl https://sh.rustup.rs -sSf | sh -s -- -y |
|
||||||
export PATH=$PATH:$HOME/.cargo/bin |
|
||||||
if ! which rustup &> /dev/null; then |
|
||||||
echo "Failed to install rustup. Performing the commit without style checking." |
|
||||||
exit 0 |
|
||||||
fi |
|
||||||
fi |
|
||||||
|
|
||||||
if ! rustup component list|grep rustfmt &> /dev/null; then |
|
||||||
echo "Installing rustfmt…" |
|
||||||
rustup component add rustfmt |
|
||||||
fi |
|
||||||
} |
|
||||||
|
|
||||||
if ! which cargo >/dev/null 2>&1 || ! cargo fmt --help >/dev/null 2>&1; then |
|
||||||
echo "Unable to check Fractal’s code style, because rustfmt could not be run." |
|
||||||
|
|
||||||
if [ ! -t 1 ]; then |
|
||||||
# No input is possible |
|
||||||
echo "Performing commit." |
|
||||||
exit 0 |
|
||||||
fi |
|
||||||
|
|
||||||
|
echo "-- Pre-commit checks --" |
||||||
|
echo "To ignore these checks next time, run: git commit --no-verify" |
||||||
|
echo "" |
||||||
|
if scripts/checks.sh; then |
||||||
echo "" |
echo "" |
||||||
echo "y: Install rustfmt via rustup" |
echo "Pre-commit checks result: ok" |
||||||
echo "n: Don't install rustfmt and perform the commit" |
elif [[ $? -eq 2 ]]; then |
||||||
echo "Q: Don't install rustfmt and abort the commit" |
echo "A missing dependency was found" |
||||||
|
echo "" |
||||||
|
echo "y: Skip checks and proceed with commit" |
||||||
|
echo "N: Abort commit" |
||||||
echo "" |
echo "" |
||||||
while true |
while true |
||||||
do |
do |
||||||
echo -n "Install rustfmt via rustup? [y/n/Q]: "; read yn < /dev/tty |
echo -n "Skip the pre-commit checks? [y/N]: "; read yn < /dev/tty |
||||||
case $yn in |
case $yn in |
||||||
[Yy]* ) install_rustfmt; break;; |
[Yy]* ) |
||||||
[Nn]* ) echo "Performing commit."; exit 0;; |
echo "Skipping checks…" |
||||||
[Qq]* | "" ) echo "Aborting commit."; exit -1 >/dev/null 2>&1;; |
exit 0 |
||||||
* ) echo "Invalid input";; |
;; |
||||||
|
[Nn]* | "" ) |
||||||
|
echo "Aborting commit" |
||||||
|
exit 1 |
||||||
|
;; |
||||||
|
* ) |
||||||
|
echo "Invalid input" |
||||||
|
;; |
||||||
esac |
esac |
||||||
done |
done |
||||||
|
|
||||||
fi |
|
||||||
|
|
||||||
echo "--Checking style--" |
|
||||||
cargo fmt --all -- --check |
|
||||||
if test $? != 0; then |
|
||||||
echo "--Checking style fail--" |
|
||||||
echo "Please fix the above issues, either manually or by running: cargo fmt --all" |
|
||||||
|
|
||||||
exit -1 |
|
||||||
else |
else |
||||||
echo "--Checking style pass--" |
echo "Pre-commit checks result: fail" |
||||||
fi |
echo "Aborting commit" |
||||||
|
exit 1 |
||||||
|
fi |
||||||
@ -0,0 +1,55 @@ |
|||||||
|
#!/bin/sh |
||||||
|
# Source: https://gitlab.gnome.org/GNOME/fractal/blob/master/hooks/pre-commit.hook |
||||||
|
|
||||||
|
install_rustfmt() { |
||||||
|
if ! which rustup &> /dev/null; then |
||||||
|
curl https://sh.rustup.rs -sSf | sh -s -- -y |
||||||
|
export PATH=$PATH:$HOME/.cargo/bin |
||||||
|
if ! which rustup &> /dev/null; then |
||||||
|
echo "Failed to install rustup." |
||||||
|
exit 2 |
||||||
|
fi |
||||||
|
fi |
||||||
|
|
||||||
|
if ! rustup component list|grep rustfmt &> /dev/null; then |
||||||
|
echo "Installing rustfmt…" |
||||||
|
rustup component add rustfmt |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
if ! which cargo >/dev/null 2>&1 || ! cargo fmt --help >/dev/null 2>&1; then |
||||||
|
echo "Unable to check Fractal’s code style, because rustfmt could not be run." |
||||||
|
|
||||||
|
if [ ! -t 1 ]; then |
||||||
|
# No input is possible |
||||||
|
echo "Performing commit." |
||||||
|
exit 0 |
||||||
|
fi |
||||||
|
|
||||||
|
echo "" |
||||||
|
echo "y: Install rustfmt via rustup" |
||||||
|
echo "N: Don't install rustfmt" |
||||||
|
|
||||||
|
echo "" |
||||||
|
while true |
||||||
|
do |
||||||
|
echo -n "Install rustfmt? [y/N]: "; read yn < /dev/tty |
||||||
|
case $yn in |
||||||
|
[Yy]* ) install_rustfmt; break;; |
||||||
|
[Nn]* | "" ) exit 2 >/dev/null 2>&1;; |
||||||
|
* ) echo "Invalid input";; |
||||||
|
esac |
||||||
|
done |
||||||
|
|
||||||
|
fi |
||||||
|
|
||||||
|
echo "--Checking style--" |
||||||
|
cargo fmt --all -- --check |
||||||
|
if test $? != 0; then |
||||||
|
echo "--Checking style fail--" |
||||||
|
echo "Please fix the above issues, either manually or by running: cargo fmt --all" |
||||||
|
|
||||||
|
exit 1 |
||||||
|
else |
||||||
|
echo "--Checking style pass--" |
||||||
|
fi |
||||||
Loading…
Reference in new issue