@@ -5,6 +5,15 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
55REPO_ROOT=" $( cd " $SCRIPT_DIR /.." && pwd) "
66BINARY=" $REPO_ROOT /gitbackup"
77
8+ if [[ -t 1 ]]; then
9+ GREEN=' \033[0;32m'
10+ RED=' \033[0;31m'
11+ BOLD=' \033[1m'
12+ RESET=' \033[0m'
13+ else
14+ GREEN=' ' RED=' ' BOLD=' ' RESET=' '
15+ fi
16+
817# Load env vars
918if [[ -f " $SCRIPT_DIR /.env" ]]; then
1019 set -a
2938# Expected repo names (same across all services)
3039EXPECTED_REPOS=" gitbackup-test-public gitbackup-test-private"
3140
41+ log () {
42+ local ts
43+ ts=$( date +%H:%M:%S)
44+ echo -e " [$ts ] $* "
45+ }
46+
47+ START_TIME=$SECONDS
48+
3249# --- Helpers ---
3350
3451pass () {
35- echo " PASS: $1 "
36- RESULTS+=(" PASS: $1 " )
52+ log " ${GREEN} PASS${RESET} : $1 "
53+ RESULTS+=(" ${GREEN} PASS${RESET} : $1 " )
3754 PASSED=$(( PASSED + 1 ))
3855}
3956
4057fail () {
41- echo " FAIL: $1 "
42- RESULTS+=(" FAIL: $1 " )
58+ log " ${RED} FAIL${RESET} : $1 "
59+ RESULTS+=(" ${RED} FAIL${RESET} : $1 " )
4360 FAILED=$(( FAILED + 1 ))
4461}
4562
@@ -48,7 +65,7 @@ check_env() {
4865 shift
4966 for var in " $@ " ; do
5067 if [[ -z " ${! var:- } " ]]; then
51- echo " Skipping $service : $var is not set"
68+ log " Skipping $service : $var is not set"
5269 return 1
5370 fi
5471 done
@@ -95,21 +112,21 @@ run_service_tests() {
95112 local extra_flags=" ${3:- } "
96113 local tmpdir
97114
98- echo " "
99- echo " === $service ($label ) ==="
115+ log " "
116+ log " ${BOLD} === $service ($label ) ===${RESET} "
100117
101118 # Test 1: Fresh clone
102119 tmpdir=$( mktemp -d)
103120 trap " rm -rf $tmpdir " RETURN
104121
105- echo " Running fresh clone..."
122+ log " Running fresh clone..."
106123 if run_gitbackup -service " $service " -backupdir " $tmpdir " $extra_flags ; then
107124 all_found=true
108125 for repo_name in $EXPECTED_REPOS ; do
109126 if check_repo_exists " $tmpdir " " $repo_name " ; then
110- echo " Found $repo_name "
127+ log " Found $repo_name "
111128 else
112- echo " Missing $repo_name "
129+ log " Missing $repo_name "
113130 all_found=false
114131 fi
115132 done
@@ -123,7 +140,7 @@ run_service_tests() {
123140 fi
124141
125142 # Test 2: Update (run again into same directory)
126- echo " Running update..."
143+ log " Running update..."
127144 if run_gitbackup -service " $service " -backupdir " $tmpdir " $extra_flags ; then
128145 all_found=true
129146 for repo_name in $EXPECTED_REPOS ; do
@@ -145,14 +162,14 @@ run_service_tests() {
145162 # Test 3: Bare clone
146163 tmpdir=$( mktemp -d)
147164
148- echo " Running bare clone..."
165+ log " Running bare clone..."
149166 if run_gitbackup -service " $service " -backupdir " $tmpdir " -bare $extra_flags ; then
150167 all_found=true
151168 for repo_name in $EXPECTED_REPOS ; do
152169 if check_bare_repo_exists " $tmpdir " " $repo_name " ; then
153- echo " Found ${repo_name} .git (bare)"
170+ log " Found ${repo_name} .git (bare)"
154171 else
155- echo " Missing ${repo_name} .git (bare)"
172+ log " Missing ${repo_name} .git (bare)"
156173 all_found=false
157174 fi
158175 done
@@ -170,22 +187,22 @@ run_service_tests() {
170187 # Test 4: Ignore private
171188 tmpdir=$( mktemp -d)
172189
173- echo " Running ignore-private clone..."
190+ log " Running ignore-private clone..."
174191 if run_gitbackup -service " $service " -backupdir " $tmpdir " -ignore-private $extra_flags ; then
175192 if check_repo_exists " $tmpdir " " gitbackup-test-public" ; then
176- echo " Found gitbackup-test-public"
193+ log " Found gitbackup-test-public"
177194 else
178- echo " Missing gitbackup-test-public"
195+ log " Missing gitbackup-test-public"
179196 fail " $service ($label ): ignore-private — public repo not found"
180197 rm -rf " $tmpdir "
181198 trap - RETURN
182199 return
183200 fi
184201 if check_repo_exists " $tmpdir " " gitbackup-test-private" ; then
185- echo " Found gitbackup-test-private (unexpected)"
202+ log " Found gitbackup-test-private (unexpected)"
186203 fail " $service ($label ): ignore-private — private repo should have been skipped"
187204 else
188- echo " Correctly skipped gitbackup-test-private"
205+ log " Correctly skipped gitbackup-test-private"
189206 pass " $service ($label ): ignore-private"
190207 fi
191208 else
@@ -197,13 +214,13 @@ run_service_tests() {
197214 # Test 5: Ignore fork
198215 tmpdir=$( mktemp -d)
199216
200- echo " Running clone without -ignore-fork (fork should be present)..."
217+ log " Running clone without -ignore-fork (fork should be present)..."
201218 if run_gitbackup -service " $service " -backupdir " $tmpdir " $extra_flags ; then
202219 if check_repo_exists " $tmpdir " " gitbackup-test-ignore-fork" ; then
203- echo " Found gitbackup-test-ignore-fork (forked repo)"
220+ log " Found gitbackup-test-ignore-fork (forked repo)"
204221 pass " $service ($label ): fork present without -ignore-fork"
205222 else
206- echo " Missing gitbackup-test-ignore-fork (forked repo)"
223+ log " Missing gitbackup-test-ignore-fork (forked repo)"
207224 fail " $service ($label ): fork present without -ignore-fork — gitbackup-test-ignore-fork not found"
208225 fi
209226 else
@@ -215,20 +232,20 @@ run_service_tests() {
215232 # Test 6: Ignore fork (with flag)
216233 tmpdir=$( mktemp -d)
217234
218- echo " Running clone with -ignore-fork..."
235+ log " Running clone with -ignore-fork..."
219236 if run_gitbackup -service " $service " -backupdir " $tmpdir " -ignore-fork $extra_flags ; then
220237 if check_repo_exists " $tmpdir " " gitbackup-test-ignore-fork" ; then
221- echo " Found gitbackup-test-ignore-fork (unexpected — should be skipped)"
238+ log " Found gitbackup-test-ignore-fork (unexpected — should be skipped)"
222239 fail " $service ($label ): ignore-fork — forked repo should have been skipped"
223240 else
224- echo " Correctly skipped gitbackup-test-ignore-fork"
241+ log " Correctly skipped gitbackup-test-ignore-fork"
225242 # Verify non-fork repos are still present
226243 all_found=true
227244 for repo_name in $EXPECTED_REPOS ; do
228245 if check_repo_exists " $tmpdir " " $repo_name " ; then
229- echo " Found $repo_name "
246+ log " Found $repo_name "
230247 else
231- echo " Missing $repo_name "
248+ log " Missing $repo_name "
232249 all_found=false
233250 fi
234251 done
@@ -246,13 +263,51 @@ run_service_tests() {
246263 trap - RETURN
247264}
248265
266+ run_starred_tests () {
267+ local service=" $1 "
268+ local label=" $2 "
269+ local extra_flags=" $3 "
270+ local tmpdir
271+
272+ log " "
273+ log " ${BOLD} === $service ($label ) ===${RESET} "
274+
275+ tmpdir=$( mktemp -d)
276+ trap " rm -rf $tmpdir " RETURN
277+
278+ log " Running starred repos clone..."
279+ if run_gitbackup -service " $service " -backupdir " $tmpdir " -use-https-clone $extra_flags ; then
280+ if check_repo_exists " $tmpdir " " gitbackup-test-public" ; then
281+ log " Found gitbackup-test-public (starred)"
282+ else
283+ log " Missing gitbackup-test-public (starred)"
284+ fail " $service ($label ): starred — gitbackup-test-public not found"
285+ rm -rf " $tmpdir "
286+ trap - RETURN
287+ return
288+ fi
289+ if check_repo_exists " $tmpdir " " gitbackup-test-private" ; then
290+ log " Found gitbackup-test-private (unexpected — not starred)"
291+ fail " $service ($label ): starred — gitbackup-test-private should not be present"
292+ else
293+ log " Correctly excluded gitbackup-test-private (not starred)"
294+ pass " $service ($label ): starred"
295+ fi
296+ else
297+ fail " $service ($label ): starred — gitbackup exited with error"
298+ fi
299+
300+ rm -rf " $tmpdir "
301+ trap - RETURN
302+ }
303+
249304# --- Main ---
250305
251306PASSED=0
252307FAILED=0
253308RESULTS=()
254309
255- echo " Building gitbackup..."
310+ log " Building gitbackup..."
256311(cd " $REPO_ROOT " && go build -o " $BINARY " .)
257312
258313for service in " ${SERVICES[@]} " ; do
@@ -261,11 +316,13 @@ for service in "${SERVICES[@]}"; do
261316 check_env github GITHUB_TOKEN || continue
262317 run_service_tests github " SSH"
263318 run_service_tests github " HTTPS" " -use-https-clone"
319+ run_starred_tests github " starred" " -github.repoType starred"
264320 ;;
265321 gitlab)
266322 check_env gitlab GITLAB_TOKEN || continue
267323 run_service_tests gitlab " SSH" " -gitlab.projectVisibility all -gitlab.projectMembershipType owner"
268324 run_service_tests gitlab " HTTPS" " -gitlab.projectVisibility all -gitlab.projectMembershipType owner -use-https-clone"
325+ run_starred_tests gitlab " starred" " -gitlab.projectVisibility all -gitlab.projectMembershipType starred"
269326 ;;
270327 bitbucket)
271328 check_env bitbucket BITBUCKET_USERNAME BITBUCKET_TOKEN || continue
@@ -276,21 +333,23 @@ for service in "${SERVICES[@]}"; do
276333 check_env forgejo FORGEJO_TOKEN || continue
277334 run_service_tests forgejo " SSH" " -githost.url https://codeberg.org"
278335 run_service_tests forgejo " HTTPS" " -githost.url https://codeberg.org -use-https-clone"
336+ run_starred_tests forgejo " starred" " -githost.url https://codeberg.org -forgejo.repoType starred"
279337 ;;
280338 esac
281339done
282340
283341# --- Summary (verbose only) ---
284342
285343if $VERBOSE ; then
286- echo " "
287- echo " =============================="
288- echo " Results: $PASSED passed, $FAILED failed"
289- echo " "
344+ log " "
345+ log " ${BOLD} ==============================${RESET} "
346+ log " Results: $PASSED passed, $FAILED failed"
347+ log " "
290348 for r in " ${RESULTS[@]} " ; do
291- echo " $r "
349+ log " $r "
292350 done
293- echo " =============================="
351+ log " Elapsed: $(( SECONDS - START_TIME)) s"
352+ log " ${BOLD} ==============================${RESET} "
294353fi
295354
296355if [[ $FAILED -gt 0 ]]; then
0 commit comments