firecracker
/
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
14set -e15
16# Audit code base
17cargo audit18# For every staged file
19for i in $(git diff --name-only --cached --diff-filter=d); do20echo $i21# Get the extension22filename=$(basename -- "$i")23extension="${filename##*.}"24if [ "$extension" = "rs" ]; then25# Read rustfmt config, replace '\n' with ','26rustfmt_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.28rustfmt $i --check --config $rustfmt_config29# Run `cargo fmt` for this file30rustfmt $i --config $rustfmt_config31fi32if [ "$extension" = "py" ]; then33# Apply formatters for this file34black $i35isort $i36fi37if [ "$extension" = "md" ]; then38mdformat $i39fi40# Add changes to this file (as a result of formatting) to the commit.41git add $i42done
43