File: githelper.sh

package info (click to toggle)
linuxcnc 1%3A2.9.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 285,604 kB
  • sloc: python: 202,568; ansic: 109,036; cpp: 99,239; tcl: 16,054; xml: 10,631; sh: 10,303; makefile: 1,255; javascript: 138; sql: 72; asm: 15
file content (94 lines) | stat: -rw-r--r-- 3,022 bytes parent folder | download
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#
# This is a bash shell fragment, intended to be sourced by scripts that
# want to work with git in the emc2 repo.
#
# Sets GIT_BRANCH to the passed in branch name; if none is passed in it
# attempts to detect the current branch (this will fail if the repo is in a
# detached HEAD state).
#
# Sets DEB_COMPONENT based on the branch.  Official release branches get
# their own component, all other branches go in "scratch".
#
# Sets GIT_TAG to the most recent signed tag (this will fall back to the
# most recent tag of any kind if no signed tag is found).
#


function githelper() {
    if [ -z "$1" ]; then
        GIT_BRANCH=$(git symbolic-ref -q --short HEAD 2>/dev/null)
        if [ -z "$GIT_BRANCH" ]; then
            GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
        fi
    else
        GIT_BRANCH="$1"
    fi

    case $GIT_BRANCH in
        master)
            MM=$(git show HEAD:VERSION | sed -E 's/^([0-9]+)\.([0-9]+).*/\1.\2/')
            GIT_TAG_GLOB="v${MM}.*"
            DEB_COMPONENT="master"
            ;;
        # release branches have names matching "number.number", which is awkward to express as a glob
        [0-9].[0-9] | [0-9].[0-9][0-9] | [0-9].[0-9][0-9][0-9] | [0-9][0-9].[0-9] | [0-9][0-9].[0-9][0-9] | [0-9][0-9].[0-9][0-9][0-9])
            GIT_TAG_GLOB="v${GIT_BRANCH}.*"
            DEB_COMPONENT=$GIT_BRANCH
            ;;
        v2.5_branch)
            GIT_TAG_GLOB="v2.5*"
            DEB_COMPONENT="v2.5_branch"
            ;;
        v2.4_branch)
            GIT_TAG_GLOB="v2.4*"
            DEB_COMPONENT="v2.4_branch"
            ;;
        *)
            GIT_TAG_GLOB="*"
            DEB_COMPONENT="scratch"
            ;;
    esac


    # use the gnupg keyring from our git repo to verify signatures on the release tags
    export GNUPGHOME=$(git rev-parse --show-toplevel)/gnupg

    NEWEST_SIGNED_TAG_UTIME=-1
    NEWEST_UNSIGNED_TAG_UTIME=-1
    for TAG in $(git tag -l "$GIT_TAG_GLOB"); do
        if ! git cat-file tag $TAG > /dev/null 2> /dev/null; then
            continue
        fi

        TAG_UTIME=$(git cat-file tag $TAG | grep tagger | awk '{print $(NF-1)-$NF*36}')

        if git tag -v "$TAG" > /dev/null 2> /dev/null; then
            # it's a valid signed tag
            if [ $TAG_UTIME -gt $NEWEST_SIGNED_TAG_UTIME ]; then
                NEWEST_SIGNED_TAG=$TAG
                NEWEST_SIGNED_TAG_UTIME=$TAG_UTIME
            fi
        else
            # unsigned tag
            if [ $TAG_UTIME -gt $NEWEST_UNSIGNED_TAG_UTIME ]; then
                NEWEST_UNSIGNED_TAG=$TAG
                NEWEST_UNSIGNED_TAG_UTIME=$TAG_UTIME
            fi
        fi

    done

    if [ $NEWEST_SIGNED_TAG_UTIME -gt -1 ]; then
        GIT_TAG="$NEWEST_SIGNED_TAG"
        return
    fi

    if [ $NEWEST_UNSIGNED_TAG_UTIME -gt -1 ]; then
        echo "no signed tags found, falling back to unsigned tags" > /dev/null 1>&2
        GIT_TAG="$NEWEST_UNSIGNED_TAG"
        return
    fi

    echo "no annotated tags found, not even unsigned" > /dev/null 1>&2
}