#!/usr/bin/env bash SCRIPT_NAME=$(basename "$0") function usage() { echo "$SCRIPT_NAME [-h] [-n]" echo echo " arguments:" echo " -h: show this help text" echo " -n: dry run mode" echo " (default: run commands)" echo echo " env vars:" echo " required:" echo " TOR_FULL_GIT_PATH: where the git repository directories reside." echo " You must set this env var, we recommend \$HOME/git/" echo " (default: fail if this env var is not set;" echo " current: $GIT_PATH)" echo echo " optional:" echo " TOR_MASTER: the name of the directory containing the tor.git clone" echo " The tor master git directory is \$GIT_PATH/\$TOR_MASTER" echo " (default: tor; current: $TOR_MASTER_NAME)" echo " TOR_WKT_NAME: the name of the directory containing the tor" echo " worktrees. The tor worktrees are:" echo " \$GIT_PATH/\$TOR_WKT_NAME/{maint-*,release-*}" echo " (default: tor-wkt; current: $TOR_WKT_NAME)" echo " we recommend that you set these env vars in your ~/.profile" } ################# # Configuration # ################# # Don't change this configuration - set the env vars in your .profile # Where are all those git repositories? GIT_PATH=${TOR_FULL_GIT_PATH:-"FULL_PATH_TO_GIT_REPOSITORY_DIRECTORY"} # The tor master git repository directory from which all the worktree have # been created. TOR_MASTER_NAME=${TOR_MASTER_NAME:-"tor"} # The worktrees location (directory). TOR_WKT_NAME=${TOR_WKT_NAME:-"tor-wkt"} ########################## # Git branches to manage # ########################## # Configuration of the branches that need pulling. The values are in order: # (1) Branch name to pull (update). # (2) Full path of the git worktree. # # As an example: # $ cd (3) # $ git checkout maint-0.3.5 (1) # $ git pull # # First set of arrays are the maint-* branch and then the release-* branch. # New arrays need to be in the WORKTREE= array else they aren't considered. MAINT_035=( "maint-0.3.5" "$GIT_PATH/$TOR_WKT_NAME/maint-0.3.5" ) MAINT_041=( "maint-0.4.1" "$GIT_PATH/$TOR_WKT_NAME/maint-0.4.1" ) MAINT_042=( "maint-0.4.2" "$GIT_PATH/$TOR_WKT_NAME/maint-0.4.2" ) MAINT_043=( "maint-0.4.3" "$GIT_PATH/$TOR_WKT_NAME/maint-0.4.3" ) MAINT_MASTER=( "master" "$GIT_PATH/$TOR_MASTER_NAME" ) RELEASE_035=( "release-0.3.5" "$GIT_PATH/$TOR_WKT_NAME/release-0.3.5" ) RELEASE_041=( "release-0.4.1" "$GIT_PATH/$TOR_WKT_NAME/release-0.4.1" ) RELEASE_042=( "release-0.4.2" "$GIT_PATH/$TOR_WKT_NAME/release-0.4.2" ) RELEASE_043=( "release-0.4.3" "$GIT_PATH/$TOR_WKT_NAME/release-0.4.3" ) # The master branch path has to be the main repository thus contains the # origin that will be used to fetch the updates. All the worktrees are created # from that repository. ORIGIN_PATH="$GIT_PATH/$TOR_MASTER_NAME" # SC2034 -- shellcheck thinks that these are unused. We know better. ACTUALLY_THESE_ARE_USED=<&1 ) validate_ret $? "$msg" else printf "\\n %s\\n" "${IWTH}$cmd${CNRM}" fi } # Pull the given branch name. function merge_branch { local cmd="git merge --ff-only origin/$1" printf " %s Merging branch origin/%s..." "$MARKER" "$1" if [ $DRY_RUN -eq 0 ]; then msg=$( eval "$cmd" 2>&1 ) validate_ret $? "$msg" else printf "\\n %s\\n" "${IWTH}$cmd${CNRM}" fi } # Go into the worktree repository. function goto_repo { if [ ! -d "$1" ]; then echo " $1: Not found. Stopping." exit 1 fi cd "$1" || exit } # Fetch the origin. No arguments. function fetch_origin { local cmd="git fetch origin" printf " %s Fetching origin..." "$MARKER" if [ $DRY_RUN -eq 0 ]; then msg=$( eval "$cmd" 2>&1 ) validate_ret $? "$msg" else printf "\\n %s\\n" "${IWTH}$cmd${CNRM}" fi } # Fetch tor-github pull requests. No arguments. function fetch_tor_github { local cmd="git fetch tor-github" printf " %s Fetching tor-github..." "$MARKER" if [ $DRY_RUN -eq 0 ]; then msg=$( eval "$cmd" 2>&1 ) validate_ret $? "$msg" else printf "\\n %s\\n" "${IWTH}$cmd${CNRM}" fi } ############### # Entry point # ############### # First, fetch tor-github. goto_repo "$ORIGIN_PATH" fetch_tor_github # Then, fetch the origin. fetch_origin # Go over all configured worktree. for ((i=0; i