File: git_ready.sh

package info (click to toggle)
mpich 4.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,184 kB
  • sloc: ansic: 1,040,629; cpp: 82,270; javascript: 40,763; perl: 27,933; python: 16,041; sh: 14,676; xml: 14,418; f90: 12,916; makefile: 9,270; fortran: 8,046; java: 4,635; asm: 324; ruby: 103; awk: 27; lisp: 19; php: 8; sed: 4
file content (59 lines) | stat: -rwxr-xr-x 1,339 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
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bash
#
# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# See file LICENSE for terms.
#

source ./buildlib/tools/codestyle.sh

ucx=://github.com/openucx/ucx
upstream=$(git remote -v  | grep -P "[\t ].*${ucx}.*[\t ].*fetch" | cut -f 1 | head -n 1)
base=$(git merge-base "$upstream"/master HEAD)

if ! git diff-index --quiet HEAD; then
    echo "error: tree not clean"
    exit 1
fi

codestyle_check_commit_title "$base"..HEAD
if [[ $? -ne 0 ]]
then
    echo "error: fix commit title"
    exit 1
fi

# Code format
module load dev/llvm-ucx || :
git clang-format --diff "$base" HEAD | patch -p1
module unload dev/llvm-ucx || :

# Codespell
codestyle_check_spell --write-changes || :

# Create commit for pre-push fixes
if ! git diff-index --quiet HEAD; then
    git add -p
    # returns 1 if cached index is not empty
    git diff --cached --exit-code || git commit -m "$title"
fi

# Pushing
if [ "${1-}" = "--push" ]
then

    opt="${2-}"
    remote="${opt%%/*}"
    branch="${opt#*/}"

    if [ "$remote" = "$opt" ] || [ -z "$remote" ] || [ -z "$branch" ]
    then
        echo "error: specify push location with '--push <remote>/<branch_name>'"
        exit 1
    fi

    cmd="git push $remote HEAD:refs/heads/$branch"
    echo "$cmd"
    echo "<enter> or <ctrl-c> to abort"
    read -r
    $cmd
fi