git-list-tor-branches.sh (4199B)
1 #!/usr/bin/env bash 2 3 # Script to be used by other git scripts, and provide a single place 4 # that lists our supported branches. To change which branches are 5 # supported, look at the end of the file that says 'edit here'. 6 7 SCRIPT_NAME=$(basename "$0") 8 9 function usage() 10 { 11 echo "$SCRIPT_NAME [-h] [-l|-s|-b|-m] [-R|-M]" 12 echo 13 echo " arguments:" 14 echo " -h: show this help text" 15 echo 16 echo " -l: list the active tor branches (default)" 17 echo " -s: list the suffixes to be used with the active tor branches" 18 echo " -b: write bash code setting WORKTREE to an array of ( branch path ) arrays" 19 echo " -m: write bash code setting WORKTREE to an array of" 20 echo " ( branch parent path suffix parent_suffix ) arrays" 21 echo 22 echo " -R: omit release branches." 23 echo " -M: omit maint branches." 24 } 25 26 # list : just a list of branch names. 27 # branch_path : For git-setup-dirs.sh and git-pull-all.sh 28 # suffix: write a list of suffixes. 29 # merge: branch, upstream, path, suffix, upstream suffix. 30 mode="list" 31 skip_maint_branches="no" 32 skip_release_branches="no" 33 34 while getopts "hblmsRM" opt ; do 35 case "$opt" in 36 h) usage 37 exit 0 38 ;; 39 b) mode="branch_path" 40 ;; 41 l) mode="list" 42 ;; 43 s) mode="suffix" 44 ;; 45 m) mode="merge" 46 ;; 47 M) skip_maint_branches="yes" 48 ;; 49 R) skip_release_branches="yes" 50 ;; 51 *) echo "Unknown option" 52 exit 1 53 ;; 54 esac 55 done 56 57 all_branch_vars=() 58 59 prev_maint_branch="" 60 prev_maint_suffix="" 61 62 branch() { 63 # The name of the branch. (Supplied by caller) Ex: maint-0.4.3 64 brname="$1" 65 66 # The name of the branch with no dots. Ex: maint-043 67 brname_nodots="${brname//./}" 68 # The name of the branch with no dots, and _ instead of -. Ex: maint_043 69 brname_nodots_uscore="${brname_nodots//-/_}" 70 # Name to use for a variable to represent the branch. Ex: MAINT_043 71 varname="${brname_nodots_uscore^^}" 72 73 is_maint="no" 74 75 # suffix: a suffix to place at the end of branches we generate with respect 76 # to this branch. Ex: _043 77 78 # location: where the branch can be found. 79 80 if [[ "$brname" == "main" ]]; then 81 suffix="_main" 82 location="\$GIT_PATH/\$TOR_MASTER_NAME" 83 elif [[ "$brname" =~ ^maint- ]]; then 84 suffix="_${brname_nodots#maint-}" 85 location="\$GIT_PATH/\$TOR_WKT_NAME/$brname" 86 is_maint="yes" 87 if [[ "$skip_maint_branches" = "yes" ]]; then 88 return 89 fi 90 elif [[ "$brname" =~ ^release- ]]; then 91 suffix="_r${brname_nodots#release-}" 92 location="\$GIT_PATH/\$TOR_WKT_NAME/$brname" 93 94 if [[ "$skip_release_branches" = "yes" ]]; then 95 return 96 fi 97 else 98 echo "Unrecognized branch type '${brname}'" >&2 99 exit 1 100 fi 101 102 all_branch_vars+=("$varname") 103 104 # Now emit the per-branch information 105 if [[ "$mode" == "branch_path" ]]; then 106 echo "${varname}=( \"$brname\" \"$location\" )" 107 elif [[ "$mode" == "merge" ]]; then 108 echo "${varname}=( \"$brname\" \"$prev_maint_branch\" \"$location\" \"$suffix\" \"$prev_maint_suffix\" )" 109 elif [[ "$mode" == "list" ]]; then 110 echo "$brname" 111 elif [[ "$mode" == "suffix" ]]; then 112 echo "$suffix" 113 else 114 echo "unknown mode $mode" >&2 115 exit 1 116 fi 117 118 if [[ "$is_maint" == "yes" ]]; then 119 prev_maint_branch="$brname" 120 prev_maint_suffix="$suffix" 121 fi 122 } 123 124 finish() { 125 if [[ "$mode" == branch_path ]] || [[ "$mode" == merge ]]; then 126 echo "WORKTREE=(" 127 for v in "${all_branch_vars[@]}"; do 128 echo " ${v}[@]" 129 done 130 echo ")" 131 elif [[ "$mode" == list ]] || [[ "$mode" == suffix ]]; then 132 # nothing to do 133 : 134 else 135 echo "unknown mode $mode" >&2 136 exit 1 137 fi 138 } 139 140 # ============================== 141 # EDIT HERE 142 # ============================== 143 # List of all branches. These must be in order, from oldest to newest, with 144 # maint before release. 145 146 branch maint-0.4.8 147 branch release-0.4.8 148 149 branch maint-0.4.9 150 branch release-0.4.9 151 152 branch main 153 154 finish