git-setup-dirs.sh 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. #!/usr/bin/env bash
  2. SCRIPT_NAME=$(basename "$0")
  3. function usage()
  4. {
  5. echo "$SCRIPT_NAME [-h] [-n] [-u]"
  6. echo
  7. echo " arguments:"
  8. echo " -h: show this help text"
  9. echo " -n: dry run mode"
  10. echo " (default: run commands)"
  11. echo " -u: if a directory or worktree already exists, use it"
  12. echo " (default: fail and exit on existing directories)"
  13. echo
  14. echo " env vars:"
  15. echo " required:"
  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)"
  20. echo
  21. echo " optional:"
  22. echo " TOR_MASTER: the name of the directory containing the tor.git clone"
  23. echo " The tor master 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 " TOR_GIT_ORIGIN_PULL: the origin remote pull URL."
  30. echo " (current: $GIT_ORIGIN_PULL)"
  31. echo " TOR_GIT_ORIGIN_PUSH: the origin remote push URL"
  32. echo " (current: $GIT_ORIGIN_PUSH)"
  33. echo " TOR_UPSTREAM_REMOTE_NAME: the default upstream remote."
  34. echo " If \$TOR_UPSTREAM_REMOTE_NAME is not 'origin', we have a"
  35. echo " separate upstream remote, and we don't push to origin."
  36. echo " (default: $DEFAULT_UPSTREAM_REMOTE)"
  37. echo " TOR_GITHUB_PULL: the tor-github remote pull URL"
  38. echo " (current: $GITHUB_PULL)"
  39. echo " TOR_GITHUB_PUSH: the tor-github remote push URL"
  40. echo " (current: $GITHUB_PUSH)"
  41. echo " TOR_EXTRA_CLONE_ARGS: extra arguments to git clone"
  42. echo " (current: $TOR_EXTRA_CLONE_ARGS)"
  43. echo " TOR_EXTRA_REMOTE_NAME: the name of an extra remote"
  44. echo " This remote is not pulled by this script or git-pull-all.sh."
  45. echo " This remote is not pushed by git-push-all.sh."
  46. echo " (current: $TOR_EXTRA_REMOTE_NAME)"
  47. echo " TOR_EXTRA_REMOTE_PULL: the extra remote pull URL."
  48. echo " (current: $TOR_EXTRA_REMOTE_PULL)"
  49. echo " TOR_EXTRA_REMOTE_PUSH: the extra remote push URL"
  50. echo " (current: $TOR_EXTRA_REMOTE_PUSH)"
  51. echo " we recommend that you set these env vars in your ~/.profile"
  52. }
  53. #################
  54. # Configuration #
  55. #################
  56. # Don't change this configuration - set the env vars in your .profile
  57. # Where are all those git repositories?
  58. GIT_PATH=${TOR_FULL_GIT_PATH:-"FULL_PATH_TO_GIT_REPOSITORY_DIRECTORY"}
  59. # The tor master git repository directory from which all the worktree have
  60. # been created.
  61. TOR_MASTER_NAME=${TOR_MASTER_NAME:-"tor"}
  62. # The worktrees location (directory).
  63. TOR_WKT_NAME=${TOR_WKT_NAME:-"tor-wkt"}
  64. # Origin repositories
  65. GIT_ORIGIN_PULL=${TOR_GIT_ORIGIN_PULL:-"https://git.torproject.org/tor.git"}
  66. GIT_ORIGIN_PUSH=${TOR_GIT_ORIGIN_PUSH:-"git@git-rw.torproject.org:tor.git"}
  67. # The upstream remote which git.torproject.org/tor.git points to.
  68. DEFAULT_UPSTREAM_REMOTE=${TOR_UPSTREAM_REMOTE_NAME:-"upstream"}
  69. # Copy the URLs from origin
  70. GIT_UPSTREAM_PULL="$GIT_ORIGIN_PULL"
  71. GIT_UPSTREAM_PUSH="$GIT_ORIGIN_PUSH"
  72. # And avoid pushing to origin if we have an upstream
  73. if [ "$DEFAULT_UPSTREAM_REMOTE" != "origin" ]; then
  74. GIT_ORIGIN_PUSH="No pushes to origin, if there is an upstream"
  75. fi
  76. # GitHub repositories
  77. GITHUB_PULL=${TOR_GITHUB_PULL:-"https://github.com/torproject/tor.git"}
  78. GITHUB_PUSH=${TOR_GITHUB_PUSH:-"No_Pushing_To_GitHub"}
  79. ##########################
  80. # Git branches to manage #
  81. ##########################
  82. # The branches and worktrees need to be modified when there is a new branch,
  83. # and when an old branch is no longer supported.
  84. # Configuration of the branches that needs merging. The values are in order:
  85. # (0) current maint/release branch name
  86. # (1) Full path of the git worktree
  87. #
  88. # First set of arrays are the maint-* branch and then the release-* branch.
  89. # New arrays need to be in the WORKTREE= array else they aren't considered.
  90. MAINT_035=( "maint-0.3.5" "$GIT_PATH/$TOR_WKT_NAME/maint-0.3.5" )
  91. MAINT_040=( "maint-0.4.0" "$GIT_PATH/$TOR_WKT_NAME/maint-0.4.0" )
  92. MAINT_041=( "maint-0.4.1" "$GIT_PATH/$TOR_WKT_NAME/maint-0.4.1" )
  93. MAINT_042=( "maint-0.4.2" "$GIT_PATH/$TOR_WKT_NAME/maint-0.4.2" )
  94. MAINT_MASTER=( "master" "$GIT_PATH/$TOR_MASTER_NAME" )
  95. RELEASE_035=( "release-0.3.5" "$GIT_PATH/$TOR_WKT_NAME/release-0.3.5" )
  96. RELEASE_040=( "release-0.4.0" "$GIT_PATH/$TOR_WKT_NAME/release-0.4.0" )
  97. RELEASE_041=( "release-0.4.1" "$GIT_PATH/$TOR_WKT_NAME/release-0.4.1" )
  98. RELEASE_042=( "release-0.4.2" "$GIT_PATH/$TOR_WKT_NAME/release-0.4.2" )
  99. # The master branch path has to be the main repository thus contains the
  100. # origin that will be used to fetch the updates. All the worktrees are created
  101. # from that repository.
  102. ORIGIN_PATH="$GIT_PATH/$TOR_MASTER_NAME"
  103. # SC2034 -- shellcheck thinks that these are unused. We know better.
  104. ACTUALLY_THESE_ARE_USED=<<EOF
  105. ${MAINT_035[0]}
  106. ${MAINT_040[0]}
  107. ${MAINT_041[0]}
  108. ${MAINT_042[0]}
  109. ${MAINT_MASTER[0]}
  110. ${RELEASE_035[0]}
  111. ${RELEASE_040[0]}
  112. ${RELEASE_041[0]}
  113. ${RELEASE_042[0]}
  114. EOF
  115. #######################
  116. # Argument processing #
  117. #######################
  118. # Controlled by the -n option. The dry run option will just output the command
  119. # that would have been executed for each worktree.
  120. DRY_RUN=0
  121. # Controlled by the -s option. The use existing option checks for existing
  122. # directories, and re-uses them, rather than creating a new directory.
  123. USE_EXISTING=0
  124. USE_EXISTING_HINT="Use existing: '$SCRIPT_NAME -u'."
  125. while getopts "hnu" opt; do
  126. case "$opt" in
  127. h) usage
  128. exit 0
  129. ;;
  130. n) DRY_RUN=1
  131. echo " *** DRY RUN MODE ***"
  132. ;;
  133. u) USE_EXISTING=1
  134. echo " *** USE EXISTING DIRECTORIES MODE ***"
  135. ;;
  136. *)
  137. echo
  138. usage
  139. exit 1
  140. ;;
  141. esac
  142. done
  143. ###########################
  144. # Git worktrees to manage #
  145. ###########################
  146. WORKTREE=(
  147. MAINT_035[@]
  148. RELEASE_035[@]
  149. MAINT_040[@]
  150. RELEASE_040[@]
  151. MAINT_041[@]
  152. RELEASE_041[@]
  153. MAINT_042[@]
  154. RELEASE_042[@]
  155. MAINT_MASTER[@]
  156. )
  157. COUNT=${#WORKTREE[@]}
  158. #############
  159. # Constants #
  160. #############
  161. # Control characters
  162. CNRM=$'\x1b[0;0m' # Clear color
  163. # Bright color
  164. BGRN=$'\x1b[1;32m'
  165. BBLU=$'\x1b[1;34m'
  166. BRED=$'\x1b[1;31m'
  167. BYEL=$'\x1b[1;33m'
  168. IWTH=$'\x1b[3;37m'
  169. # Strings for the pretty print.
  170. MARKER="${BBLU}[${BGRN}+${BBLU}]${CNRM}"
  171. SUCCESS="${BGRN}success${CNRM}"
  172. SKIPPED="${BYEL}skipped${CNRM}"
  173. FAILED="${BRED}failed${CNRM}"
  174. ####################
  175. # Helper functions #
  176. ####################
  177. # Validate the given returned value (error code), print success or failed. The
  178. # second argument is the error output in case of failure, it is printed out.
  179. # On failure, this function exits.
  180. function validate_ret
  181. {
  182. if [ "$1" -eq 0 ]; then
  183. printf "%s\\n" "$SUCCESS"
  184. else
  185. printf "%s\\n" "$FAILED"
  186. printf " %s\\n" "$2"
  187. exit 1
  188. fi
  189. }
  190. # Validate the given returned value (error code), print success, skipped, or
  191. # failed. If $USE_EXISTING is 0, fail on error, otherwise, skip on error.
  192. # The second argument is the error output in case of failure, it is printed
  193. # out. On failure, this function exits.
  194. function validate_ret_skip
  195. {
  196. if [ "$1" -ne 0 ]; then
  197. if [ "$USE_EXISTING" -eq "0" ]; then
  198. # Fail and exit with error
  199. validate_ret "$1" "$2 $USE_EXISTING_HINT"
  200. else
  201. printf "%s\\n" "$SKIPPED"
  202. printf " %s\\n" "${IWTH}$2${CNRM}"
  203. # Tell the caller to skip the rest of the function
  204. return 0
  205. fi
  206. fi
  207. # Tell the caller to continue
  208. return 1
  209. }
  210. # Create a directory, and any missing enclosing directories.
  211. # If the directory already exists: fail if $USE_EXISTING is 0, otherwise skip.
  212. function make_directory
  213. {
  214. local cmd="mkdir -p '$1'"
  215. printf " %s Creating directory %s..." "$MARKER" "$1"
  216. local check_cmd="[ ! -d '$1' ]"
  217. msg=$( eval "$check_cmd" 2>&1 )
  218. if validate_ret_skip $? "Directory already exists."; then
  219. return
  220. fi
  221. if [ $DRY_RUN -eq 0 ]; then
  222. msg=$( eval "$cmd" 2>&1 )
  223. validate_ret $? "$msg"
  224. else
  225. printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
  226. fi
  227. }
  228. # Create a symlink from the first argument to the second argument
  229. # If the link already exists: fail if $USE_EXISTING is 0, otherwise skip.
  230. function make_symlink
  231. {
  232. local cmd="ln -s '$1' '$2'"
  233. printf " %s Creating symlink from %s to %s..." "$MARKER" "$1" "$2"
  234. local check_cmd="[ ! -e '$2' ]"
  235. msg=$( eval "$check_cmd" 2>&1 )
  236. if validate_ret_skip $? "File already exists."; then
  237. return
  238. fi
  239. if [ $DRY_RUN -eq 0 ]; then
  240. msg=$( eval "$cmd" 2>&1 )
  241. validate_ret $? "$msg"
  242. else
  243. printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
  244. fi
  245. }
  246. # Go into the directory or repository, even if $DRY_RUN is non-zero.
  247. # If the directory does not exist, fail and log an error.
  248. # Otherwise, silently succeed.
  249. function goto_dir
  250. {
  251. if ! cd "$1" 1>/dev/null 2>/dev/null ; then
  252. printf " %s Changing to directory %s..." "$MARKER" "$1"
  253. validate_ret 1 "$1: Not found. Stopping."
  254. fi
  255. }
  256. # Clone a repository into a directory.
  257. # If the directory already exists: fail if $USE_EXISTING is 0, otherwise skip.
  258. function clone_repo
  259. {
  260. local cmd="git clone $TOR_EXTRA_CLONE_ARGS '$1' '$2'"
  261. printf " %s Cloning %s into %s..." "$MARKER" "$1" "$2"
  262. local check_cmd="[ ! -d '$2' ]"
  263. msg=$( eval "$check_cmd" 2>&1 )
  264. if validate_ret_skip $? "Directory already exists."; then
  265. # If we skip the clone, we need to do a fetch
  266. goto_dir "$ORIGIN_PATH"
  267. fetch_remote "origin"
  268. return
  269. fi
  270. if [ $DRY_RUN -eq 0 ]; then
  271. msg=$( eval "$cmd" 2>&1 )
  272. validate_ret $? "$msg"
  273. else
  274. printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
  275. fi
  276. }
  277. # Add a remote by name and URL.
  278. # If the remote already exists: fail if $USE_EXISTING is 0, otherwise skip.
  279. function add_remote
  280. {
  281. local cmd="git remote add '$1' '$2'"
  282. printf " %s Adding remote %s at %s..." "$MARKER" "$1" "$2"
  283. local check_cmd="git remote get-url '$1'"
  284. msg=$( eval "$check_cmd" 2>&1 )
  285. ret=$?
  286. # We don't want a remote, so we invert the exit status
  287. if validate_ret_skip $(( ! ret )) \
  288. "Remote already exists for $1 at $msg."; then
  289. return
  290. fi
  291. if [ $DRY_RUN -eq 0 ]; then
  292. msg=$( eval "$cmd" 2>&1 )
  293. validate_ret $? "$msg"
  294. else
  295. printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
  296. fi
  297. }
  298. # Set a remote's push URL by name and URL.
  299. function set_remote_push
  300. {
  301. local cmd="git remote set-url --push '$1' '$2'"
  302. printf " %s Setting remote %s push URL to '%s'..." "$MARKER" "$1" "$2"
  303. if [ $DRY_RUN -eq 0 ]; then
  304. msg=$( eval "$cmd" 2>&1 )
  305. validate_ret $? "$msg"
  306. else
  307. printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
  308. fi
  309. }
  310. # Fetch a remote by name.
  311. function fetch_remote
  312. {
  313. local cmd="git fetch '$1'"
  314. printf " %s Fetching %s..." "$MARKER" "$1"
  315. if [ $DRY_RUN -eq 0 ]; then
  316. msg=$( eval "$cmd" 2>&1 )
  317. validate_ret $? "$msg"
  318. else
  319. printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
  320. fi
  321. }
  322. # Replace the fetch configs for a remote with config if they match a pattern.
  323. function replace_fetch_config
  324. {
  325. local cmd="git config --replace-all remote.'$1'.fetch '$2' '$3'"
  326. printf " %s Replacing %s fetch configs for '%s'..." \
  327. "$MARKER" "$1" "$3"
  328. if [ $DRY_RUN -eq 0 ]; then
  329. msg=$( eval "$cmd" 2>&1 )
  330. validate_ret $? "$msg"
  331. else
  332. printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
  333. fi
  334. }
  335. # Set up the tor-github PR config, so tor-github/pr/NNNN/head points to GitHub
  336. # PR NNNN. In some repositories, "/head" is optional.
  337. function set_tor_github_pr_fetch_config
  338. {
  339. # Standard branches
  340. replace_fetch_config tor-github \
  341. "+refs/heads/*:refs/remotes/tor-github/*" \
  342. "refs/heads"
  343. # PRs
  344. replace_fetch_config "tor-github" \
  345. "+refs/pull/*:refs/remotes/tor-github/pr/*" \
  346. "refs/pull.*pr"
  347. }
  348. # Add a new worktree for branch at path.
  349. # If the directory already exists: fail if $USE_EXISTING is 0, otherwise skip.
  350. function add_worktree
  351. {
  352. local cmd="git worktree add '$2' '$1'"
  353. printf " %s Adding worktree for %s at %s..." "$MARKER" "$1" "$2"
  354. local check_cmd="[ ! -d '$2' ]"
  355. msg=$( eval "$check_cmd" 2>&1 )
  356. if validate_ret_skip $? "Directory already exists."; then
  357. return
  358. fi
  359. if [ $DRY_RUN -eq 0 ]; then
  360. msg=$( eval "$cmd" 2>&1 )
  361. validate_ret $? "$msg"
  362. else
  363. printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
  364. fi
  365. }
  366. # Switch to the given branch name.
  367. # If the branch does not exist: fail.
  368. function switch_branch
  369. {
  370. local cmd="git checkout '$1'"
  371. printf " %s Switching branch to %s..." "$MARKER" "$1"
  372. if [ $DRY_RUN -eq 0 ]; then
  373. msg=$( eval "$cmd" 2>&1 )
  374. validate_ret $? "$msg"
  375. else
  376. printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
  377. fi
  378. }
  379. # Checkout a new branch with the given branch name.
  380. # If the branch already exists: fail if $USE_EXISTING is 0, otherwise skip.
  381. function new_branch
  382. {
  383. local cmd="git checkout -b '$1'"
  384. printf " %s Creating new branch %s..." "$MARKER" "$1"
  385. local check_cmd="git branch --list '$1'"
  386. msg=$( eval "$check_cmd" 2>&1 )
  387. if validate_ret_skip $? "Branch already exists."; then
  388. return
  389. fi
  390. if [ $DRY_RUN -eq 0 ]; then
  391. msg=$( eval "$cmd" 2>&1 )
  392. validate_ret $? "$msg"
  393. else
  394. printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
  395. fi
  396. }
  397. # Switch to an existing branch, or checkout a new branch with the given
  398. # branch name.
  399. function switch_or_new_branch
  400. {
  401. local cmd="git rev-parse --verify '$1'"
  402. if [ $DRY_RUN -eq 0 ]; then
  403. # Call switch_branch if there is a branch, or new_branch if there is not
  404. msg=$( eval "$cmd" 2>&1 )
  405. RET=$?
  406. if [ $RET -eq 0 ]; then
  407. # Branch: (commit id)
  408. switch_branch "$1"
  409. elif [ $RET -eq 128 ]; then
  410. # Not a branch: "fatal: Needed a single revision"
  411. new_branch "$1"
  412. else
  413. # Unexpected return value
  414. validate_ret $RET "$msg"
  415. fi
  416. else
  417. printf "\\n %s\\n" "${IWTH}$cmd${CNRM}, then depending on the result:"
  418. switch_branch "$1"
  419. new_branch "$1"
  420. fi
  421. }
  422. # Set the upstream for branch to upstream.
  423. function set_upstream
  424. {
  425. # Note the argument order is swapped
  426. local cmd="git branch --set-upstream-to='$2' '$1'"
  427. printf " %s Setting upstream for %s to %s..." "$MARKER" "$1" "$2"
  428. if [ $DRY_RUN -eq 0 ]; then
  429. msg=$( eval "$cmd" 2>&1 )
  430. validate_ret $? "$msg"
  431. else
  432. printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
  433. fi
  434. }
  435. ###############
  436. # Entry point #
  437. ###############
  438. printf "%s Setting up the repository and remote %s\\n" "$MARKER" \
  439. "${BYEL}origin${CNRM}"
  440. # First, fetch the origin.
  441. ORIGIN_PARENT=$(dirname "$ORIGIN_PATH")
  442. make_directory "$ORIGIN_PARENT"
  443. # This is just cd with an error check
  444. goto_dir "$ORIGIN_PARENT"
  445. # clone repository / origin remote
  446. clone_repo "$GIT_ORIGIN_PULL" "$TOR_MASTER_NAME"
  447. goto_dir "$ORIGIN_PATH"
  448. set_remote_push "origin" "$GIT_ORIGIN_PUSH"
  449. # upstream remote, if different to origin
  450. if [ "$DEFAULT_UPSTREAM_REMOTE" != "origin" ]; then
  451. printf "%s Setting up remote %s\\n" "$MARKER" \
  452. "${BYEL}$DEFAULT_UPSTREAM_REMOTE${CNRM}"
  453. add_remote "$DEFAULT_UPSTREAM_REMOTE" "$GIT_UPSTREAM_PULL"
  454. set_remote_push "$DEFAULT_UPSTREAM_REMOTE" "$GIT_UPSTREAM_PUSH"
  455. fetch_remote "$DEFAULT_UPSTREAM_REMOTE"
  456. fi
  457. # GitHub remote
  458. printf "%s Setting up remote %s\\n" "$MARKER" "${BYEL}tor-github${CNRM}"
  459. # Add remote
  460. add_remote "tor-github" "$GITHUB_PULL"
  461. set_remote_push "tor-github" "$GITHUB_PUSH"
  462. # Add custom fetch for PRs
  463. set_tor_github_pr_fetch_config
  464. # Now fetch them all
  465. fetch_remote "tor-github"
  466. # Extra remote
  467. if [ "$TOR_EXTRA_REMOTE_NAME" ]; then
  468. printf "%s Setting up remote %s\\n" "$MARKER" \
  469. "${BYEL}$TOR_EXTRA_REMOTE_NAME${CNRM}"
  470. # Add remote
  471. add_remote "$TOR_EXTRA_REMOTE_NAME" "$TOR_EXTRA_REMOTE_PULL"
  472. set_remote_push "$TOR_EXTRA_REMOTE_NAME" "$TOR_EXTRA_REMOTE_PUSH"
  473. # But leave it to the user to decide if they want to fetch it
  474. #fetch_remote "$TOR_EXTRA_REMOTE_NAME"
  475. fi
  476. # Go over all configured worktree.
  477. for ((i=0; i<COUNT; i++)); do
  478. branch=${!WORKTREE[$i]:0:1}
  479. repo_path=${!WORKTREE[$i]:1:1}
  480. printf "%s Handling branch %s\\n" "$MARKER" "${BYEL}$branch${CNRM}"
  481. # We cloned the repository, and master is the default branch
  482. if [ "$branch" = "master" ]; then
  483. if [ "$TOR_MASTER_NAME" != "master" ]; then
  484. # Set up a master link in the worktree directory
  485. make_symlink "$repo_path" "$GIT_PATH/$TOR_WKT_NAME/master"
  486. fi
  487. else
  488. # git makes worktree directories if they don't exist
  489. add_worktree "origin/$branch" "$repo_path"
  490. fi
  491. goto_dir "$repo_path"
  492. switch_or_new_branch "$branch"
  493. set_upstream "$branch" "origin/$branch"
  494. done
  495. echo
  496. echo "Remember to copy the git hooks from tor/scripts/git/*.git-hook to"
  497. echo "$ORIGIN_PATH/.git/hooks/*"