File: pre-commit.hook

package info (click to toggle)
warp 0.9.2-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,804 kB
  • sloc: python: 391; sh: 177; makefile: 31
file content (85 lines) | stat: -rwxr-xr-x 2,260 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
# Source: https://gitlab.gnome.org/GNOME/fractal/blob/main/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 2>&1 || ! cargo fmt --help >/dev/null 2>&1; then
    echo "Unable to check the project’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"

    echo ""
    while true
    do
        echo -n "Install rustfmt via rustup? [y/n/Q]: "; read yn < /dev/tty
        case $yn in
            [Yy]* ) install_rustfmt; break;;
            [Nn]* ) echo "Performing commit."; exit 0;;
            [Qq]* | "" ) echo "Aborting commit."; exit -1 >/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

echo -n "--Checking manifest and generated sources--"
./build-aux/generate-manifest.bash 2> /dev/null
if test $? != 0; then
  echo " (skipped)"
else
  echo ""
fi

git diff --exit-code build-aux/app.drey.Warp.Devel.json
if test $? != 0; then
    echo "--Checking manifest fail--"
    exit -1
fi

git diff --exit-code build-aux/cargo-sources.json
if test $? != 0; then
    echo "--Checking cargo sources fail--"
    exit -1
fi

echo "--Checking POTFILES--"
./build-aux/generate-potfile.sh 2> /dev/null
git diff --exit-code po/POTFILES.in
if test $? != 0; then
    echo "--Checking POTFILES fail--"
    exit -1
fi