xref: /aosp_15_r20/external/toolchain-utils/toolchain_utils_githooks/pre-push.real (revision 760c253c1ed00ce9abd48f8546f08516e57485fe)
1*760c253cSXin Li#!/bin/bash
2*760c253cSXin Li#
3*760c253cSXin Li# Copyright 2015 Google LLC
4*760c253cSXin Li#
5*760c253cSXin Li# This is a pre-push hook that does the following before uploading a
6*760c253cSXin Li# CL for review:
7*760c253cSXin Li# 1) check that python sources have been formatted with yapf.
8*760c253cSXin Li# 2) allows the user to run the unit tests.
9*760c253cSXin Li
10*760c253cSXin Limydir="$(dirname "$(readlink -m "$0")")"
11*760c253cSXin Li
12*760c253cSXin Liz40=0000000000000000000000000000000000000000
13*760c253cSXin Li
14*760c253cSXin Liwhile IFS=' ' read local_ref local_sha remote_ref remote_sha; do
15*760c253cSXin Li  if [[ "$local_sha" != $z40 ]]; then
16*760c253cSXin Li    if [[ "$remote_sha" == $z40 ]]; then
17*760c253cSXin Li      # New branch, examine commit on top of branch.
18*760c253cSXin Li      range="$local_sha"
19*760c253cSXin Li    else
20*760c253cSXin Li      # Update to existing branch, examine new commits
21*760c253cSXin Li      range="$remote_sha..$local_sha"
22*760c253cSXin Li    fi
23*760c253cSXin Li    all_files="$(git show --pretty="format:" --name-only "${range}")"
24*760c253cSXin Li    # Note that ${all_files} may include files that were deleted. Hence, we
25*760c253cSXin Li    # ignore any complaints about missing files.
26*760c253cSXin Li    IGNORE_MISSING=1 "${mydir}/check-presubmit" ${all_files} || exit 1
27*760c253cSXin Li  fi
28*760c253cSXin Lidone
29*760c253cSXin Li
30*760c253cSXin Liexit 0
31