aboutsummaryrefslogtreecommitdiff
path: root/scripts/git/git-list-tor-branches.sh
blob: d6b30f064f539616b4876c5794df8e0d971a4b8f (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env bash

# Script to be used by other git scripts, and provide a single place
# that lists our supported branches.  To change which branches are
# supported, look at the end of the file that says 'edit here'.

SCRIPT_NAME=$(basename "$0")

function usage()
{
    echo "$SCRIPT_NAME [-h] [-l|-s|-b|-m] [-R]"
    echo
    echo "  arguments:"
    echo "   -h: show this help text"
    echo
    echo "   -l: list the active tor branches (default)"
    echo "   -s: list the suffixes to be used with the active tor branches"
    echo "   -b: write bash code setting WORKTREE to an array of ( branch path ) arrays"
    echo "   -m: write bash code setting WORKTREE to an array of"
    echo "       ( branch parent path suffix parent_suffix ) arrays"
    echo
    echo "   -R: omit release branches."
}

# list : just a list of branch names.
# branch_path : For git-setup-dirs.sh and git-pull-all.sh
# suffix: write a list of suffixes.
# merge: branch, upstream, path, suffix, upstream suffix.
mode="list"
skip_release_branches="no"

while getopts "hblmsR" opt ; do
    case "$opt" in
        h) usage
           exit 0
           ;;
        b) mode="branch_path"
           ;;
        l) mode="list"
           ;;
        s) mode="suffix"
           ;;
        m) mode="merge"
           ;;
        R) skip_release_branches="yes"
           ;;
        *) echo "Unknown option"
           exit 1
           ;;
    esac
done

all_branch_vars=()

prev_maint_branch=""
prev_maint_suffix=""

branch() {
    # The name of the branch. (Supplied by caller)  Ex: maint-0.4.3
    brname="$1"

    # The name of the branch with no dots. Ex: maint-043
    brname_nodots="${brname//./}"
    # The name of the branch with no dots, and _ instead of -. Ex: maint_043
    brname_nodots_uscore="${brname_nodots//-/_}"
    # Name to use for a variable to represent the branch. Ex: MAINT_043
    varname="${brname_nodots_uscore^^}"

    is_maint="no"

    # suffix: a suffix to place at the end of branches we generate with respect
    # to this branch.  Ex: _043

    # location: where the branch can be found.

    if [[ "$brname" == "master" ]]; then
        suffix="_master"
        location="\$GIT_PATH/\$TOR_MASTER_NAME"
    elif [[ "$brname" =~ ^maint- ]]; then
        suffix="_${brname_nodots#maint-}"
        location="\$GIT_PATH/\$TOR_WKT_NAME/$brname"
        is_maint="yes"
    elif [[ "$brname" =~ ^release- ]]; then
        suffix="_r${brname_nodots#release-}"
        location="\$GIT_PATH/\$TOR_WKT_NAME/$brname"

        if [[ "$skip_release_branches" = "yes" ]]; then
            return
        fi
    else
        echo "Unrecognized branch type '${brname}'" >&2
        exit 1
    fi

    all_branch_vars+=("$varname")

    # Now emit the per-branch information
    if [[ "$mode" == "branch_path" ]]; then
        echo "${varname}=( \"$brname\" \"$location\" )"
    elif [[ "$mode" == "merge" ]]; then
        echo "${varname}=( \"$brname\" \"$prev_maint_branch\" \"$location\" \"$suffix\" \"$prev_maint_suffix\" )"
    elif [[ "$mode" == "list" ]]; then
        echo "$brname"
    elif [[ "$mode" == "suffix" ]]; then
        echo "$suffix"
    else
        echo "unknown mode $mode" >&2
        exit 1
    fi

    if [[ "$is_maint" == "yes" ]]; then
        prev_maint_branch="$brname"
        prev_maint_suffix="$suffix"
    fi
}

finish() {
    if [[ "$mode" == branch_path ]] || [[ "$mode" == merge ]]; then
        echo "WORKTREE=("
        for v in "${all_branch_vars[@]}"; do
            echo "  ${v}[@]"
        done
        echo ")"
    elif [[ "$mode" == list ]] || [[ "$mode" == suffix ]]; then
        # nothing to do
        :
    else
        echo "unknown mode $mode" >&2
        exit 1
    fi
}

# ==============================
# EDIT HERE
# ==============================
# List of all branches.  These must be in order, from oldest to newest, with
# maint before release.

branch maint-0.3.5
branch release-0.3.5

branch maint-0.4.1
branch release-0.4.1

branch maint-0.4.2
branch release-0.4.2

branch maint-0.4.3
branch release-0.4.3

branch master

finish