mirror of
https://github.com/rustdesk/qemu-display.git
synced 2026-06-22 16:51:11 +00:00
Initial commit
This commit is contained in:
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/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. 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 || ! cargo fmt --help &> /dev/null; 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 and perform the commit"
|
||||
echo "Q: Don't install rustfmt and abort the commit"
|
||||
|
||||
while true; do
|
||||
read -p "Install rustfmt via rustup? [y/n/Q]: " yn
|
||||
case $yn in
|
||||
[Yy]* ) install_rustfmt; break;;
|
||||
[Nn]* ) echo "Performing commit."; exit 0;;
|
||||
[Qq]* | "" ) echo "Aborting commit."; exit -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
|
||||
Reference in New Issue
Block a user