firecracker

Форк
0
/
pre-commit 
42 строки · 1.4 Кб
1
#!/bin/sh
2

3
# Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
# SPDX-License-Identifier: Apache-2.0
5

6
# We avoid checks which require building firecracker due to the issues this introduces when
7
# attempting to interact with the repository from an enviroment in which you cannot build
8
# firecracker.
9

10
# This will only fail when a staged file does not contain an appropriate license
11
# when formatting is incorrect this will automaticalt rectify it.
12

13
# Exit immediately when encountering a non-zero command
14
set -e
15

16
# Audit code base
17
cargo audit
18
# For every staged file
19
for i in $(git diff --name-only --cached --diff-filter=d); do
20
    echo $i
21
    # Get the extension
22
    filename=$(basename -- "$i")
23
    extension="${filename##*.}"
24
    if [ "$extension" = "rs" ]; then
25
        # Read rustfmt config, replace '\n' with ','
26
        rustfmt_config="$(sed -z "s/\n/,/g;s/,$/\n/" ./tests/fmt.toml)"
27
        # We first do a check run, this will fail when it finds a non-matching license.
28
        rustfmt $i --check --config $rustfmt_config
29
        # Run `cargo fmt` for this file
30
        rustfmt $i --config $rustfmt_config
31
    fi
32
    if [ "$extension" = "py" ]; then
33
        # Apply formatters for this file
34
        black $i
35
        isort $i
36
    fi
37
    if [ "$extension" = "md" ]; then
38
        mdformat $i
39
    fi
40
    # Add changes to this file (as a result of formatting) to the commit.
41
    git add $i
42
done
43

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.