3 SCRIPT_NAME
=$
(basename "$0")
7 echo "$SCRIPT_NAME [-h] [-n]"
10 echo " -h: show this help text"
11 echo " -n: dry run mode"
12 echo " (default: run commands)"
16 echo " TOR_FULL_GIT_PATH: where the git repository directories reside."
17 echo " You must set this env var, we recommend \$HOME/git/"
18 echo " (default: fail if this env var is not set;"
19 echo " current: $GIT_PATH)"
22 echo " TOR_MASTER: the name of the directory containing the tor.git clone"
23 echo " The primary tor git directory is \$GIT_PATH/\$TOR_MASTER"
24 echo " (default: tor; current: $TOR_MASTER_NAME)"
25 echo " TOR_WKT_NAME: the name of the directory containing the tor"
26 echo " worktrees. The tor worktrees are:"
27 echo " \$GIT_PATH/\$TOR_WKT_NAME/{maint-*,release-*}"
28 echo " (default: tor-wkt; current: $TOR_WKT_NAME)"
29 echo " we recommend that you set these env vars in your ~/.profile"
36 # Don't change this configuration - set the env vars in your .profile
38 # Where are all those git repositories?
39 GIT_PATH
=${TOR_FULL_GIT_PATH:-"FULL_PATH_TO_GIT_REPOSITORY_DIRECTORY"}
40 # The primary tor git repository directory from which all the worktree have
42 TOR_MASTER_NAME
=${TOR_MASTER_NAME:-"tor"}
43 # The worktrees location (directory).
44 TOR_WKT_NAME
=${TOR_WKT_NAME:-"tor-wkt"}
46 ##########################
47 # Git branches to manage #
48 ##########################
51 eval "$(git-list-tor-branches.sh -b)"
54 # The main branch path has to be the main repository thus contains the
55 # origin that will be used to fetch the updates. All the worktrees are created
56 # from that repository.
57 ORIGIN_PATH
="$GIT_PATH/$TOR_MASTER_NAME"
61 #######################
62 # Argument processing #
63 #######################
65 # Controlled by the -n option. The dry run option will just output the command
66 # that would have been executed for each worktree.
69 while getopts "hn" opt
; do
75 echo " *** DRY DRUN MODE ***"
90 CNRM
=$
'\x1b[0;0m' # Clear color
99 # Strings for the pretty print.
100 MARKER
="${BBLU}[${BGRN}+${BBLU}]${CNRM}"
101 SUCCESS
="${BGRN}ok${CNRM}"
102 FAILED
="${BRED}failed${CNRM}"
108 # Validate the given returned value (error code), print success or failed. The
109 # second argument is the error output in case of failure, it is printed out.
110 # On failure, this function exits.
111 function validate_ret
113 if [ "$1" -eq 0 ]; then
114 printf "%s\\n" "$SUCCESS"
116 printf "%s\\n" "$FAILED"
122 # Switch to the given branch name.
123 function switch_branch
125 local cmd
="git checkout $1"
126 printf " %s Switching branch to %s..." "$MARKER" "$1"
127 if [ $DRY_RUN -eq 0 ]; then
128 msg
=$
( eval "$cmd" 2>&1 )
129 validate_ret $?
"$msg"
131 printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
135 # Pull the given branch name.
136 function merge_branch
138 local cmd
="git merge --ff-only origin/$1"
139 printf " %s Merging branch origin/%s..." "$MARKER" "$1"
140 if [ $DRY_RUN -eq 0 ]; then
141 msg
=$
( eval "$cmd" 2>&1 )
142 validate_ret $?
"$msg"
144 printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
148 # Go into the worktree repository.
151 if [ ! -d "$1" ]; then
152 echo " $1: Not found. Stopping."
158 # Fetch the origin. No arguments.
159 function fetch_origin
161 local cmd
="git fetch origin"
162 printf "%s Fetching origin..." "$MARKER"
163 if [ $DRY_RUN -eq 0 ]; then
164 msg
=$
( eval "$cmd" 2>&1 )
165 validate_ret $?
"$msg"
167 printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
175 # Get into our origin repository.
176 goto_repo
"$ORIGIN_PATH"
181 # Go over all configured worktree.
182 for ((i
=0; i
<COUNT
; i
++)); do
183 current
=${!WORKTREE[$i]:0:1}
184 repo_path
=${!WORKTREE[$i]:1:1}
186 printf "%s Handling branch %s\\n" "$MARKER" "${BYEL}$current${CNRM}"
188 # Go into the worktree to start merging.
189 goto_repo
"$repo_path"
190 # Checkout the current branch
191 switch_branch
"$current"
192 # Update the current branch by merging the origin to get the latest.
193 merge_branch
"$current"