File: pre-commit-check-for-rebasing.sh

package info (click to toggle)
mpich 4.3.0%2Breally4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 419,120 kB
  • sloc: ansic: 1,215,557; cpp: 74,755; javascript: 40,763; f90: 20,649; sh: 18,463; xml: 14,418; python: 14,397; perl: 13,772; makefile: 9,279; fortran: 8,063; java: 4,553; asm: 324; ruby: 176; lisp: 19; php: 8; sed: 4
file content (47 lines) | stat: -rwxr-xr-x 1,366 bytes parent folder | download | duplicates (3)
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
#!/bin/bash
##
## Copyright (C) by Argonne National Laboratory
##     See COPYRIGHT in top-level directory
##

# This hook prevent from pushing a branch that is not rebased on
# latest MPICH main branch.
#
# It fetches the hash of the latest main branch from github and compares
# the local branch. It returns 1 if either the hash of the latest
# main branch does not exist in the local git repo or the branch needs
# rebasing.
#
# To enable this hook, rename this file to "pre-push" and put it
# under .git/hooks

remote="$1"
url="$2"

z40=0000000000000000000000000000000000000000

GITHUB_REPO="pmodels/mpich"
MAIN_BRANCH="main"

# getting the latest main branch hash from github
MAIN_SHA=$(curl -s https://api.github.com/repos/${GITHUB_REPO}/git/ref/heads/${MAIN_BRANCH} | grep sha | sed -e 's/.*: "//g' | sed -e 's/".*//g')
if test "$(git cat-file -t $MAIN_SHA)" != "commit" ; then
    echo "The repo is behind the https://github.com/pmodels/mpich"
    echo "Run git fetch to update"
    exit 1
fi

IFS=' '
while read local_ref local_sha remote_ref remote_sha
do
    if test "${local_sha}" != $z40 ; then
        LOCAL_BASE_SHA=$(git merge-base ${MAIN_SHA} ${local_sha})

        if test "${LOCAL_BASE_SHA}" != "${MAIN_SHA}" ; then
            echo "Your branch need to rebased on latest main branch before push"
            exit 1
        fi
    fi
done

exit 0