GitRoot

Craft your forge, Build your project, Grow your community freely
 1#!/usr/bin/env bash
 2
 3# SPDX-FileCopyrightText: 2026 Romain Maneschi <romain@gitroot.dev>
 4#
 5# SPDX-License-Identifier: EUPL-1.2
 6
 7_init() {
 8    local SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
 9    source "${SCRIPT_DIR}/report.sh"
10    source "${SCRIPT_DIR}/git.sh"
11}
12
13_init
14unset -f _init
15
16# push_and_wait <remote> <branch>...
17#   Push then sleep 0.1 sec then push again, display time waiting after all.
18function push_and_wait() {
19    start=`date +%s.%N`
20    quiet_git push "$@"
21    sleep 0.1
22    local attempts=0
23    while true; do
24        ((attempts++))
25        output=$(LANG=C git push "$@" 2>&1)
26        if echo "$output" | grep -q "\[rejected\]"; then
27            break
28        fi
29        if [ $attempts -gt 50 ]; then
30            report "🛑 Timeout : too much try"
31            break
32        fi
33        sleep 0.5
34    done
35    end=`date +%s.%N`
36    runtime=$( echo "$end - $start" | bc -l )
37    min=$(echo "$runtime / 60" | bc)
38    sec=$(echo "$runtime % 60" | bc | xargs printf "%06.3f")
39    report "🕐 waiting pipeline ${min}m ${sec}s"
40}