33set -euo pipefail
44
55SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
6+ export SCRIPT_DIR
7+
8+ # peek.php renders a live lane of output per parallel job. Its use is
9+ # optional: it degrades to a plain passthrough on platforms that cannot
10+ # support the display (e.g. Windows) and can be disabled with NO_PEEK=1.
11+ PEEK_PHP=" ${SCRIPT_DIR} /peek.php"
12+ export PEEK_PHP
13+
14+ # Parallel jobs run behind the peek display, where an interactive prompt is
15+ # instantly overdrawn and would hang the run waiting for input nobody can
16+ # see. Git and ssh prompt on /dev/tty (not stdin), so disable prompting
17+ # entirely: failures then surface as visible errors in the job's lane.
18+ # - GIT_TERMINAL_PROMPT=0: no credential/username prompts from git itself.
19+ # - BatchMode=yes: ssh fails instead of asking for passphrases or host key
20+ # confirmation (keys served by an ssh-agent keep working). Only set when
21+ # GIT_SSH_COMMAND is not already customized.
22+ # - GIT_MERGE_AUTOEDIT=no: a non-fast-forward pull keeps the default merge
23+ # message instead of opening an editor.
24+ export GIT_TERMINAL_PROMPT=0
25+ export GIT_MERGE_AUTOEDIT=no
26+ if [[ -z " ${GIT_SSH_COMMAND:- } " ]]; then
27+ export GIT_SSH_COMMAND=" ssh -oBatchMode=yes"
28+ fi
629
730if ! command -v jq & > /dev/null; then
831 echo " Required command 'jq' is not installed or not available in PATH." >&2
@@ -119,8 +142,11 @@ get_destination() {
119142 fi
120143}
121144
122- CLONE_LIST=()
123- UPDATE_FOLDERS=()
145+ # One task per repository: sync-repository.sh clones missing folders and
146+ # refreshes existing ones. Running a single parallel pass over all
147+ # repositories keeps all ${CORES} slots busy for the whole run, instead of
148+ # a clone stage and a refresh stage separated by a barrier.
149+ TASK_LIST=()
124150
125151while IFS=$' \t ' read -r name clone_url ssh_url; do
126152 if [[ -z " ${name} " ]]; then
@@ -133,21 +159,14 @@ while IFS=$'\t' read -r name clone_url ssh_url; do
133159
134160 destination=$( get_destination " ${name} " )
135161
136- if [[ ! -d " ${destination} " ]]; then
137- if [[ " ${PROTOCOL} " == " ssh" ]]; then
138- CLONE_LIST+=(" ${destination} " $' \t ' " ${ssh_url} " )
139- else
140- CLONE_LIST+=(" ${destination} " $' \t ' " ${clone_url} " )
141- fi
162+ if [[ " ${PROTOCOL} " == " ssh" ]]; then
163+ TASK_LIST+=(" ${destination} " $' \t ' " ${ssh_url} " )
164+ else
165+ TASK_LIST+=(" ${destination} " $' \t ' " ${clone_url} " )
142166 fi
143-
144- UPDATE_FOLDERS+=(" ${destination} " )
145167done <<< " ${REPOSITORIES}"
146168
147- if [[ ${# CLONE_LIST[@]} -gt 0 ]]; then
148- printf ' %s\n' " ${CLONE_LIST[@]} " | xargs -n2 -P" ${CORES} " bash " ${SCRIPT_DIR} /clone-repository.sh"
149- fi
150-
151- if [[ ${# UPDATE_FOLDERS[@]} -gt 0 ]]; then
152- printf ' %s\n' " ${UPDATE_FOLDERS[@]} " | xargs -P" ${CORES} " -I% php " ${SCRIPT_DIR} /refresh-repository.php" %
169+ if [[ ${# TASK_LIST[@]} -gt 0 ]]; then
170+ printf ' %s\n' " ${TASK_LIST[@]} " | php " ${PEEK_PHP} " -- xargs -n2 -P" ${CORES} " \
171+ bash -c ' exec php "${PEEK_PHP}" run -n "$1" -- bash "${SCRIPT_DIR}/sync-repository.sh" "$1" "$2"' _
153172fi
0 commit comments