GitRoot
craft your forge, build your project, grow your community freely
1#!/usr/bin/env bash
2
3# SPDX-FileCopyrightText: 2025 Romain Maneschi <romain@gitroot.dev>
4#
5# SPDX-License-Identifier: EUPL-1.2
6
7trap 'catch $LINENO' ERR
8
9EXPECTED_ERROR=0
10
11catch() {
12 if [[ $EXPECTED_ERROR == 0 ]]; then
13 echo "🛑 unexpected error line $1"
14 exit 1
15 fi
16 report "🟢 expected err line $1"
17}
18
19quiet_git() {
20 echo "🚀 git $@" >> /tmp/mylog.txt
21 GIT_TRACE=false GIT_TRACE_PACKET=false git "$@" &>> /tmp/mylog.txt
22}
23
24report() {
25 echo "$1" >> /tmp/mylog.txt
26 echo "$1"
27}
28
29mySleep() {
30 echo "🕐 $1" >> /tmp/mylog.txt
31 sleep $1
32}
33
34function wait_for() {
35 start=`date +%s`
36 timeout=100
37 until [ $timeout -le 0 ] || (grep -q $1 $2 &> /dev/null); do
38 sleep 0.1
39 timeout=$(( timeout - 1 ))
40 done
41 if [ $timeout -le 0 ]; then
42 return 1
43 fi
44 end=`date +%s`
45 echo "🕐 $@ in `expr $end - $start` seconds"
46}
47
48function wait_ls() {
49 start=`date +%s`
50 timeout=500
51 until [ $timeout -le 0 ] || [ $(ls $1 | wc -l) -eq 3 ]; do
52 sleep 0.1
53 timeout=$(( timeout - 1 ))
54 done
55 if [ $timeout -le 0 ]; then
56 return 1
57 fi
58 end=`date +%s`
59 echo "🕐 $@ in `expr $end - $start` seconds"
60 mySleep 0.3
61}
62
63EXIT_CODE=0
64
65SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
66
67SERVER_PORT="4545"
68SERVER_URL=${1:-"127.0.0.1:$SERVER_PORT"}
69SERVER_DATA_DIR="/tmp/gitrootData"
70
71ROOT_REPO_NAME="root"
72ROOT_REPO_URL="ssh://user@${SERVER_URL}/${ROOT_REPO_NAME}"
73REPO1_NAME="repo1"
74REPO1_URL="ssh://user@${SERVER_URL}/${REPO1_NAME}"
75REPO2_NAME="repo2"
76REPO2_URL="ssh://user@${SERVER_URL}/${REPO2_NAME}"
77REPO3_NAME="repo3"
78REPO3_URL="ssh://user@${SERVER_URL}/${REPO3_NAME}"
79
80SSH_KEY="${SCRIPT_DIR}/user1/ed25519"
81SSH_KEY2="${SCRIPT_DIR}/user2/ed25519"
82
83##### clean
84report "🏁 clean"
85
86cd /tmp
87rm -rf ${SERVER_DATA_DIR}
88rm -rf ${ROOT_REPO_NAME}
89rm -rf ${ROOT_REPO_NAME}_2
90rm -rf ${REPO1_NAME}
91rm -rf ${REPO2_NAME}
92rm -rf ${REPO1_NAME}_2
93rm -rf ${REPO2_NAME}_2
94rm -rf ${REPO3_NAME}
95rm -f /tmp/mylog.txt
96APP=$(lsof -i tcp:${SERVER_PORT} | awk 'NR!=1 {print $2}')
97if [ -z "$APP" ]; then
98 report "🟢 Gitroot not launched"
99else
100 kill ${APP}
101 report "🟢 Gitroot killed"
102fi
103ssh-keygen -f "$HOME/.ssh/known_hosts" -R "[127.0.0.1]:$SERVER_PORT"
104
105##### launch gitroot
106report "🏁 launch gitroot"
107
108cd ${SCRIPT_DIR}/../server
109GIT_TRACE_PACKET=false go run -race . -data="${SERVER_DATA_DIR}" &>> /tmp/mylog.txt &
110
111wait_for "starting SSH server on" /tmp/mylog.txt
112
113##### forgeConfig
114report "🏁 forgeConfig"
115
116cd /tmp
117quiet_git clone --quiet -c "core.sshCommand=ssh -i ${SSH_KEY} -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new" ${ROOT_REPO_URL}
118cd ${ROOT_REPO_NAME}
119.gitroot/init.sh --pubKey "${SSH_KEY}.pub" --privKey "${SSH_KEY}" --email forgeConfig@gitroot.dev --name forgeConfig >> /tmp/mylog.txt
120
121DIFF=$(git status --porcelain .gitroot/allowed_signers)
122if [[ $DIFF =~ "M .gitroot/allowed_signers" ]]; then
123 report "🟢 ${ROOT_REPO_NAME}/.gitroot/allowed_signers"
124else
125 report "🛑 ${ROOT_REPO_NAME}/.gitroot/allowed_signers"
126 EXIT_CODE=1
127fi
128
129DIFF=$(git status --porcelain .gitroot/users.yml)
130if [[ $DIFF =~ "M .gitroot/users.yml" ]]; then
131 report "🟢 ${ROOT_REPO_NAME}/.gitroot/users.yml"
132else
133 report "🛑 ${ROOT_REPO_NAME}/.gitroot/users.yml"
134 EXIT_CODE=1
135fi
136
137quiet_git add .
138quiet_git commit -m "init user"
139report "🟢 ${ROOT_REPO_NAME} commit user"
140
141printf "${REPO1_NAME}:\n defaultbranch: main" >> .gitroot/repositories.yml
142quiet_git add .
143quiet_git commit -m "create first repo"
144quiet_git push origin main
145report "🟢 ${ROOT_REPO_NAME} push first repo"
146
147mySleep 0.05
148
149##### Repo1
150report "🏁 Repo1"
151
152cd /tmp
153GIT_SSH_COMMAND="ssh -i ${SSH_KEY} -o IdentitiesOnly=yes" quiet_git clone --quiet "${REPO1_URL}"
154cd ${REPO1_NAME}
155.gitroot/init.sh --pubKey "${SSH_KEY}.pub" --privKey "${SSH_KEY}" --email repo1@gitroot.dev --name user1 >> /tmp/mylog.txt
156
157DIFF=$(git status --porcelain .gitroot/allowed_signers)
158if [[ $DIFF =~ "M .gitroot/allowed_signers" ]]; then
159 report "🟢 ${REPO1_NAME}/.gitroot/allowed_signers"
160else
161 report "🛑 ${REPO1_NAME}/.gitroot/allowed_signers"
162 EXIT_CODE=1
163fi
164
165DIFF2=$(git status --porcelain .gitroot/users.yml)
166if [[ $DIFF2 =~ "M .gitroot/users.yml" ]]; then
167 report "🟢 ${REPO1_NAME}/.gitroot/users.yml"
168else
169 report "🛑 ${REPO1_NAME}/.gitroot/users.yml"
170 EXIT_CODE=1
171fi
172
173quiet_git add .
174quiet_git commit -m "init user"
175report "🟢 ${REPO1_NAME} commit user"
176
177quiet_git checkout -b "branch1"
178quiet_git push origin main branch1
179report "🟢 ${REPO1_NAME} push main+branch1"
180quiet_git checkout main
181quiet_git push origin :branch1
182report "🟢 ${REPO1_NAME} delete :branch1"
183quiet_git push origin main
184report "🟢 ${REPO1_NAME} push empty main"
185
186##### first plugin
187report "🏁 first plugin"
188
189cd /tmp/${ROOT_REPO_NAME}
190echo "- url: '${SCRIPT_DIR}/../plugins/ladybug/ladybug-0.0.2.wasm'" >> .gitroot/plugins.yml
191quiet_git add .
192quiet_git commit -m "init ladybug plugin"
193printf "\n${REPO2_NAME}:\n defaultbranch: main" >> .gitroot/repositories.yml
194quiet_git add .
195quiet_git commit -m "create second repo"
196quiet_git push origin main
197report "🟢 ${ROOT_REPO_NAME} push first plugin and second repo"
198
199wait_ls "${SERVER_DATA_DIR}/data/plugins/ladybug"
200
201if [[ $(ls "${SERVER_DATA_DIR}/data/plugins/ladybug" | wc -l) -eq 3 ]]; then
202 report "🟢 ${SERVER_DATA_DIR}/data/plugins/ladybug loaded"
203else
204 report "🛑 ${SERVER_DATA_DIR}/data/plugins/ladybug not downloaded"
205 EXIT_CODE=1
206fi
207
208quiet_git pull origin main
209
210if grep -Fxq " name: ladybug" .gitroot/plugins.yml
211then
212 report "🟢 ${ROOT_REPO_NAME} plugin ladybug initialized"
213else
214 report "🛑 ${ROOT_REPO_NAME} plugin ladybug not initialized"
215 EXIT_CODE=1
216fi
217
218if grep -Fxq " version: 0.0.2" .gitroot/plugins.yml
219then
220 report "🟢 ${ROOT_REPO_NAME} plugin ladybug version initialized"
221else
222 report "🛑 ${ROOT_REPO_NAME} plugin ladybug version not initialized"
223 EXIT_CODE=1
224fi
225
226if grep -Fxq " metadata:" .gitroot/plugins.yml
227then
228 report "🟢 ${ROOT_REPO_NAME} plugin config initialized"
229else
230 report "🛑 ${ROOT_REPO_NAME} not initialized"
231 EXIT_CODE=1
232fi
233
234if grep -Fxq " - ladybug@localhost" .gitroot/users.yml
235then
236 report "🟢 ${ROOT_REPO_NAME} plugin user initialized"
237else
238 report "🛑 ${ROOT_REPO_NAME} plugin user not initialized"
239 EXIT_CODE=1
240fi
241
242cd /tmp
243GIT_SSH_COMMAND="ssh -i ${SSH_KEY} -o IdentitiesOnly=yes" quiet_git clone --quiet "${REPO2_URL}"
244cd ${REPO2_NAME}
245.gitroot/init.sh --pubKey "${SSH_KEY}.pub" --privKey "${SSH_KEY}" --email repo2@gitroot.dev --name user1 >> /tmp/mylog.txt
246
247if grep -Fxq " metadata:" .gitroot/plugins.yml
248then
249 report "🟢 ${REPO2_NAME} plugin config initialized"
250else
251 report "🛑 ${REPO2_NAME} not initialized"
252 EXIT_CODE=1
253fi
254
255if grep -q " - path: issues/\\*\\*/\\*.md" .gitroot/plugins.yml
256then
257 report "🟢 ${REPO2_NAME} plugin path initialized"
258else
259 report "🛑 ${REPO2_NAME} not initialized"
260 EXIT_CODE=1
261fi
262
263sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
264
265mkdir issues
266echo "#my Issue" >> issues/1.md
267echo "Beatiful issue" >> issues/1.md
268quiet_git add .
269quiet_git commit -m "first issue in second repo"
270quiet_git push origin main
271report "🟢 ${REPO2_NAME} first issue in second repo"
272
273mySleep 0.05
274
275quiet_git pull
276
277if grep -q "priority: 50" issues/1.md
278then
279 report "🟢 issues/1.md initialized"
280else
281 report "🛑 issues/1.md not initialized"
282 EXIT_CODE=1
283fi
284
285##### repo1 should have issue available
286report "🏁 repo1 should have issue available"
287
288cd /tmp/${REPO1_NAME}
289
290quiet_git pull
291
292if grep -q " - path: issues/\\*\\*/\\*.md" .gitroot/plugins.yml
293then
294 report "🟢 ${REPO1_NAME} plugin path initialized"
295else
296 report "🛑 ${REPO1_NAME} not initialized"
297 EXIT_CODE=1
298fi
299
300sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
301
302mkdir issues
303echo "#my Issue" >> issues/1.md
304echo "Beatiful issue" >> issues/1.md
305quiet_git add .
306quiet_git commit -m "first issue in first repo"
307quiet_git push origin main
308report "🟢 ${REPO1_NAME} first issue in first repo"
309
310mySleep 0.05
311
312quiet_git pull
313
314if grep -q "priority: 50" issues/1.md
315then
316 report "🟢 issues/1.md initialized"
317else
318 report "🛑 issues/1.md not initialized"
319 EXIT_CODE=1
320fi
321
322##### user2 rights
323report "🏁 user2 rights"
324
325cd /tmp
326GIT_SSH_COMMAND="ssh -i ${SSH_KEY2} -o IdentitiesOnly=yes" quiet_git clone --quiet "${REPO1_URL}" ${REPO1_NAME}_2
327cd ${REPO1_NAME}_2
328.gitroot/init.sh --pubKey "${SSH_KEY2}.pub" --privKey "${SSH_KEY2}" --email user2repo1@gitroot.dev --name user2 >> /tmp/mylog.txt
329
330echo "#my Issue" >> issues/cac-1.md
331echo "Beatiful issue" >> issues/cac-1.md
332
333quiet_git add .
334quiet_git commit -m "user2 config and an issue"
335EXPECTED_ERROR=1
336quiet_git push origin main
337if [[ "$?" == "0" ]]; then
338 report "🛑 user2 has push on main in repo1"
339 EXIT_CODE=1
340else
341 report "🟢 user2 can not push on main in repo1"
342fi
343EXPECTED_ERROR=0
344
345quiet_git reset --soft HEAD~1
346quiet_git checkout -b user2_branch_on_repo1
347quiet_git add .
348quiet_git commit -m "user2 config and an issue"
349quiet_git push origin user2_branch_on_repo1
350
351if [[ "$?" == "0" ]]; then
352 report "🟢 user2 can push on user2_branch_on_repo1 branch in repo1"
353else
354 report "🛑 user2 can not push on user2_branch_on_repo1 branch in repo1"
355 EXIT_CODE=1
356fi
357
358mySleep 0.05
359quiet_git pull origin user2_branch_on_repo1
360
361if grep -q "priority: 50" issues/cac-1.md
362then
363 report "🟢 issues/cac-1.md initialized"
364else
365 report "🛑 issues/cac-1.md not initialized"
366 EXIT_CODE=1
367fi
368
369echo "New readme" > "README.md"
370quiet_git add .
371quiet_git commit -m "update readme"
372quiet_git push origin user2_branch_on_repo1
373
374if [[ "$?" == "0" ]]; then
375 report "🟢 user2 can push on user2_branch_on_repo1 branch in repo1 second time"
376else
377 report "🛑 user2 can not push on user2_branch_on_repo1 branch in repo1 second time"
378 EXIT_CODE=1
379fi
380
381quiet_git checkout main
382
383cd /tmp/${REPO1_NAME}
384quiet_git fetch origin user2_branch_on_repo1
385quiet_git checkout user2_branch_on_repo1
386
387echo "New readme by user 1" > "README.md"
388quiet_git add .
389quiet_git commit -m "update readme"
390quiet_git push origin user2_branch_on_repo1
391report "🟢 user1 can push on user2_branch_on_repo1 branch in repo1"
392
393quiet_git checkout main
394
395##### verify commit
396report "🏁 verify commits"
397cd /tmp/${ROOT_REPO_NAME}
398git reflog show main | awk '{ print $1 }' | xargs git verify-commit &> /dev/null
399report "🟢 ${ROOT_REPO_NAME}"
400
401cd /tmp/${REPO1_NAME}
402git reflog show main | awk '{ print $1 }' | xargs git verify-commit &> /dev/null
403report "🟢 ${REPO1_NAME}"
404
405cd /tmp/${REPO2_NAME}
406git reflog show main | awk '{ print $1 }' | xargs git verify-commit &> /dev/null
407report "🟢 ${REPO2_NAME}"
408
409##### second plugin
410report "🏁 second plugin"
411
412cd /tmp/${ROOT_REPO_NAME}
413echo "- url: '${SCRIPT_DIR}/../plugins/silo/silo-0.0.2.wasm'" >> .gitroot/plugins.yml
414quiet_git add .
415quiet_git commit -m "init silo plugin"
416quiet_git push origin main
417echo "🟢 ${ROOT_REPO_NAME} push second plugin"
418
419wait_ls "${SERVER_DATA_DIR}/data/plugins/silo"
420
421quiet_git pull origin main
422
423cd /tmp/${REPO1_NAME}
424
425quiet_git pull
426
427if grep -q "title: "Roadmaps"" .gitroot/plugins.yml
428then
429 report "🟢 ${REPO1_NAME} plugin path initialized"
430else
431 report "🛑 ${REPO1_NAME} not initialized"
432 EXIT_CODE=1
433fi
434
435sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
436
437echo "---" >> issues/roadmap1.md
438echo "id: 22C3" >> issues/roadmap1.md
439echo "priority: 50" >> issues/roadmap1.md
440echo "assignee: null" >> issues/roadmap1.md
441echo "kind: 'roadmap'" >> issues/roadmap1.md
442echo "---" >> issues/roadmap1.md
443echo "# step 1: conquers the world" >> issues/roadmap1.md
444echo "" >> issues/roadmap1.md
445echo "To do that just imagine the world is small." >> issues/roadmap1.md
446
447echo "---" >> issues/roadmap2.md
448echo "id: 22C3" >> issues/roadmap2.md
449echo "priority: 10" >> issues/roadmap2.md
450echo "assignee: null" >> issues/roadmap2.md
451echo "kind: 'roadmap'" >> issues/roadmap2.md
452echo "---" >> issues/roadmap2.md
453echo "# step 2: profit" >> issues/roadmap2.md
454echo "" >> issues/roadmap2.md
455echo "Finally take in peace." >> issues/roadmap2.md
456
457quiet_git add .
458quiet_git commit -m "active silo and build first roadmap ticket"
459quiet_git push origin main
460
461mySleep 0.1
462
463quiet_git pull
464
465if grep -q "issues/roadmap1.md" boards/roadmap.md
466then
467 report "🟢 ${REPO1_NAME} roadmap initialized"
468else
469 report "🛑 ${REPO1_NAME} roadmap not initialized"
470 EXIT_CODE=1
471fi
472
473if grep -q "issues/1.md" boards/issues.md
474then
475 report "🟢 ${REPO1_NAME} issues board initialized"
476else
477 report "🛑 ${REPO1_NAME} issues board not initialized"
478 EXIT_CODE=1
479fi
480
481if grep -q "issues/1.md" boards/triage.md
482then
483 report "🟢 ${REPO1_NAME} triage board initialized"
484else
485 report "🛑 ${REPO1_NAME} triage board not initialized"
486 EXIT_CODE=1
487fi
488
489quiet_git pull --rebase origin main
490
491for (( i=0; i<=50; i++ ))
492do
493 echo "# My issue $i" >> issues/issue_$i.md
494 echo "" >> issues/issue_$i.md
495 echo "Beatiful issue" >> issues/issue_$i.md
496done
497
498quiet_git add .
499quiet_git commit -m "create lot of issues"
500quiet_git push origin main
501
502mySleep 0.5
503
504quiet_git pull
505
506for (( i=0; i<=50; i++ ))
507do
508 PRIO=$(shuf -i 0-99 -n 1)
509 sed -i -e "s/priority: 50/priority: $PRIO/g" issues/issue_$i.md
510done
511
512quiet_git add .
513quiet_git commit -m "update random prio of lot of issues"
514quiet_git push origin main
515
516mySleep 0.05
517
518quiet_git pull
519
520##### Repo2 don't allow anonymous contrib
521report "🏁 Repo2 don't allow anonymous contrib"
522
523cd /tmp/${REPO2_NAME}
524
525quiet_git pull
526
527echo "" >> .gitroot/users.yml
528echo "\"*\":" >> .gitroot/users.yml
529echo " branches:" >> .gitroot/users.yml
530echo " - name: \"*\"" >> .gitroot/users.yml
531echo " users: []" >> .gitroot/users.yml
532
533quiet_git add .
534quiet_git commit -m "block all modifications of anonymous users"
535quiet_git push origin main
536
537cd /tmp
538GIT_SSH_COMMAND="ssh -i ${SSH_KEY2} -o IdentitiesOnly=yes" quiet_git clone --quiet "${REPO2_URL}" ${REPO2_NAME}_2
539cd ${REPO2_NAME}_2
540.gitroot/init.sh --pubKey "${SSH_KEY2}.pub" --privKey "${SSH_KEY2}" --email user2repo2@gitroot.dev --name user2 >> /tmp/mylog.txt
541
542quiet_git checkout -b tryToAddMe
543quiet_git add .
544quiet_git commit -m "user2 config"
545
546EXPECTED_ERROR=1
547quiet_git push origin tryToAddMe
548if [[ "$?" == "0" ]]; then
549 report "🛑 user2 can push on tryToAddMe branch in repo2"
550 EXIT_CODE=1
551else
552 report "🟢 user2 can not push on tryToAddMe branch in repo2"
553fi
554EXPECTED_ERROR=0
555
556##### User2 can add issue in repo1 on branch user2_issue_on_repo1
557report "🏁 User2 can add issue in repo1 on branch user2_issue_on_repo1"
558
559cd /tmp/${REPO1_NAME}_2
560
561quiet_git pull origin main
562
563quiet_git checkout -b user2_issue_on_repo1
564
565echo "# My issue" >> issues/2.md
566echo "" >> issues/2.md
567echo "This is my issue" >> issues/2.md
568
569quiet_git add .
570quiet_git commit -m "user2 issue 1"
571
572echo "---" >> issues/roadmap3.md
573echo "id: 22E3" >> issues/roadmap3.md
574echo "priority: 40" >> issues/roadmap3.md
575echo "assignee: null" >> issues/roadmap3.md
576echo "kind: 'roadmap'" >> issues/roadmap3.md
577echo "---" >> issues/roadmap3.md
578echo "# step 3: give" >> issues/roadmap3.md
579echo "" >> issues/roadmap3.md
580echo "Just fun." >> issues/roadmap3.md
581
582quiet_git add .
583quiet_git commit -m "user2 roadmap 3"
584
585quiet_git push origin user2_issue_on_repo1 :user2_branch_on_repo1
586
587mySleep 0.05
588
589quiet_git pull origin user2_issue_on_repo1
590
591if grep -q "id:" issues/2.md
592then
593 report "🟢 ${REPO1_NAME}_2 issues/2.md initialized"
594else
595 report "🛑 ${REPO1_NAME}_2 issues/2.md not initialized"
596 EXIT_CODE=1
597fi
598
599if grep -q "step 3: give" boards/roadmap.md
600then
601 report "🛑 ${REPO1_NAME}_2 boards/roadmap should not be updated has silo is only on main"
602 EXIT_CODE=1
603else
604 report "🟢 ${REPO1_NAME}_2 boards/roadmap not updated"
605fi
606
607quiet_git checkout -b user2_issue2_on_repo1
608
609echo "# My issue" >> issues/3.md
610echo "" >> issues/3.md
611echo "This is my issue" >> issues/3.md
612
613quiet_git add .
614quiet_git commit -m "user2 issue 2"
615quiet_git push origin user2_issue2_on_repo1
616
617mySleep 0.05
618
619quiet_git pull origin user2_issue2_on_repo1
620
621if grep -q "id:" issues/3.md
622then
623 report "🟢 ${REPO1_NAME}_2 issues/3.md initialized"
624else
625 report "🛑 ${REPO1_NAME}_2 issues/3.md not initialized"
626 EXIT_CODE=1
627fi
628
629NB_SILO=$(grep "step 3: give" boards/roadmap.md | wc -l)
630if [[ "$NB_SILO" == "0" ]]; then
631 report "🟢 ${REPO1_NAME}_2 silo has not been called"
632else
633 report "🛑 ${REPO1_NAME}_2 silo has been called $NB_SILO times"
634 EXIT_CODE=1
635fi
636
637##### User1 push force in repo1 on main
638report "🏁 User1 push force in repo1 on main"
639cd /tmp/${REPO1_NAME}
640mySleep 0.1
641quiet_git pull
642echo "not authorized" > issues/1.md
643quiet_git add .
644quiet_git commit --amend --no-edit
645
646EXPECTED_ERROR=1
647quiet_git push -f origin main
648if [[ "$?" == "0" ]]; then
649 report "🛑 user1 can push force on main"
650 EXIT_CODE=1
651else
652 report "🟢 user1 can not push force on main"
653fi
654EXPECTED_ERROR=0
655quiet_git reset --hard origin/HEAD
656
657##### User2 push force in repo1 on branch user2_branch2_on_repo1
658report "🏁 User2 push force in repo1 on branch user2_branch2_on_repo1"
659
660cd /tmp/${REPO1_NAME}_2
661quiet_git checkout main
662quiet_git checkout -b user2_branch2_on_repo1
663
664#add a commit
665cd /tmp/${REPO1_NAME}
666quiet_git checkout main
667echo "hello" >> README.md
668quiet_git add .
669quiet_git commit -m "fake commit"
670quiet_git push origin main
671
672mySleep 0.1
673
674cd /tmp/${REPO1_NAME}_2
675echo "---" >> issues/roadmap4.md
676echo "id: 22C3" >> issues/roadmap4.md
677echo "priority: 50" >> issues/roadmap4.md
678echo "assignee: null" >> issues/roadmap4.md
679echo "kind: 'roadmap'" >> issues/roadmap4.md
680echo "---" >> issues/roadmap4.md
681echo "# step 1: conquers the world" >> issues/roadmap4.md
682echo "" >> issues/roadmap4.md
683echo "To do that just imagine the world is small." >> issues/roadmap4.md
684
685quiet_git add .
686quiet_git commit -m "roadmap4"
687quiet_git push origin user2_branch2_on_repo1
688
689quiet_git checkout main
690quiet_git pull --rebase origin main
691quiet_git checkout user2_branch2_on_repo1
692
693quiet_git rebase -X ours main
694report "🟢 Rebase ok"
695
696quiet_git push -f origin user2_branch2_on_repo1
697mySleep 0.05
698report "🟢 Push -f ok"
699
700NB_SILO=$(grep "step 1:" boards/roadmap.md | wc -l)
701if [[ "$NB_SILO" == "1" ]]; then
702 report "🟢 ${REPO1_NAME}_2 silo has not been called"
703else
704 report "🛑 ${REPO1_NAME}_2 silo has been called $NB_SILO times"
705 EXIT_CODE=1
706fi
707
708##### Add grafter plugin in repo1
709report "🏁 Add grafter plugin in repo1"
710
711cd /tmp/${ROOT_REPO_NAME}
712echo "- url: '${SCRIPT_DIR}/../plugins/grafter/grafter-0.0.2.wasm'" >> .gitroot/plugins.yml
713quiet_git add .
714quiet_git commit -m "init grafter plugin"
715quiet_git push origin main
716
717wait_ls "${SERVER_DATA_DIR}/data/plugins/grafter"
718quiet_git pull origin main
719
720cd /tmp/${REPO1_NAME}
721quiet_git pull origin main
722sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
723report "🟢 ${REPO1_NAME} grafter plugin initialized"
724quiet_git add .
725quiet_git commit -m "active grafter plugin"
726quiet_git push origin main
727
728mySleep 0.05
729
730quiet_git pull origin main
731
732report "🟢 ${REPO1_NAME} grafter plugin activated"
733quiet_git checkout -b graft_something
734echo "hello" >> tada.md
735quiet_git add .
736quiet_git commit -m "first graft"
737quiet_git push origin graft_something
738
739mySleep 0.2
740
741quiet_git pull origin graft_something
742NB_STATUS_DRAFT=$(grep "status: draft" grafts/graft_something.md | wc -l)
743if [[ $NB_STATUS_DRAFT -ge 1 ]]; then
744 report "🟢 ${REPO1_NAME} status: draft ok"
745else
746 report "🛑 ${REPO1_NAME} status: draft ko"
747 EXIT_CODE=1
748fi
749report "🟢 ${REPO1_NAME} first graft created"
750
751rm issues/1.md
752quiet_git add .
753quiet_git commit -m "rm issue first graft"
754echo "second" > issues/2.md
755quiet_git add .
756quiet_git commit -m "second issue first graft"
757mv issues/roadmap1.md issues/roadmap.md
758quiet_git add .
759quiet_git commit -m "move roadmap first graft"
760quiet_git push origin graft_something
761
762mySleep 0.2
763
764quiet_git pull origin graft_something
765NB_PUSH=$(grep "Push " grafts/graft_something.md | wc -l)
766NB_COMMIT=$(grep "### " grafts/graft_something.md | wc -l)
767if [[ "$NB_COMMIT" == "6" ]] && [[ "$NB_PUSH" == "3" ]]; then
768 report "🟢 ${REPO1_NAME} graft has 3 push and 6 commits"
769else
770 report "🛑 ${REPO1_NAME} graft has $NB_PUSH push and $NB_COMMIT commits"
771 EXIT_CODE=1
772fi
773
774NB_COMMIT=$(git log --oneline graft_something ^main | wc -l)
775if [[ $NB_COMMIT -eq 9 ]]; then
776 report "🟢 ${REPO1_NAME} has 9 commits on branch graft_something"
777else
778 report "🛑 ${REPO1_NAME} has $NB_COMMIT commits on branch graft_something"
779 EXIT_CODE=1
780fi
781
782sed -i -e 's/status: draft/status: review/g' grafts/graft_something.md
783quiet_git add .
784quiet_git commit -m "review first graft"
785quiet_git push origin graft_something
786
787mySleep 0.3
788
789quiet_git pull origin graft_something
790NB_STATUS_DRAFT=$(grep "status: draft" grafts/graft_something.md | wc -l)
791if [[ "$NB_STATUS_DRAFT" == "0" ]]; then
792 report "🟢 ${REPO1_NAME} status no more draft"
793else
794 report "🛑 ${REPO1_NAME} status: draft ko"
795 EXIT_CODE=1
796fi
797NB_REVIEWERS=$(grep "reviewers: " grafts/graft_something.md | wc -l)
798if [[ "$NB_REVIEWERS" == "1" ]]; then
799 report "🟢 ${REPO1_NAME} reviewers added"
800else
801 report "🛑 ${REPO1_NAME} reviewers ko"
802 EXIT_CODE=1
803fi
804NB_MENTION_OF_REVIEW=$(grep "review first graft" grafts/graft_something.md | wc -l)
805if [[ "$NB_MENTION_OF_REVIEW" == "0" ]]; then
806 report "🟢 ${REPO1_NAME} commit review skipped"
807else
808 report "🛑 ${REPO1_NAME} commit review not skipped"
809 EXIT_CODE=1
810fi
811report "🟢 ${REPO1_NAME} first graft ready to review"
812
813echo "second is 2" > issues/2.md
814quiet_git add .
815quiet_git commit -m "second issue review first graft"
816quiet_git push origin graft_something
817
818mySleep 0.3
819
820quiet_git pull origin graft_something
821NB_DIFF=$(grep -F '```diff' grafts/graft_something.md | wc -l)
822if [[ "$NB_DIFF" == "2" ]]; then
823 report "🟢 ${REPO1_NAME} diff added"
824else
825 report "🛑 ${REPO1_NAME} diff ko $NB_DIFF"
826 EXIT_CODE=1
827fi
828
829sed -i -e 's/status: review/status: merge/g' grafts/graft_something.md
830quiet_git add .
831quiet_git commit -m "merge first graft"
832quiet_git push origin graft_something
833
834mySleep 0.5
835
836quiet_git checkout main
837quiet_git pull --rebase origin main
838quiet_git fetch --prune
839BRANCH_EXIST=$(git branch -r | grep "origin/graft_something" | wc -l)
840if [[ "$BRANCH_EXIST" == "0" ]]; then
841 report "🟢 ${REPO1_NAME} branch graft_something deleted"
842else
843 report "🛑 ${REPO1_NAME} branch graft_something no deleted"
844 EXIT_CODE=1
845fi
846
847# TODO reactive after go-git v6
848# report "🟢 ${REPO1_NAME} recreate branch graft_something for test shallow-exclude"
849# quiet_git push origin graft_something
850
851##### Add apex plugin in repo1
852report "🏁 Add apex plugin in repo1"
853
854cd /tmp/${ROOT_REPO_NAME}
855echo "- url: '${SCRIPT_DIR}/../plugins/apex/apex-0.0.2.wasm'" >> .gitroot/plugins.yml
856quiet_git add .
857quiet_git commit -m "init apex plugin"
858quiet_git push origin main
859
860wait_ls "${SERVER_DATA_DIR}/data/plugins/apex"
861quiet_git pull origin main
862report "🟢 ${ROOT_REPO_NAME} apex plugin installed"
863
864cd /tmp/${REPO1_NAME}
865quiet_git pull origin main
866sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
867report "🟢 ${REPO1_NAME} apex plugin initialized"
868quiet_git add .
869quiet_git commit -m "active apex plugin"
870quiet_git push origin main
871
872mySleep 1
873
874quiet_git pull origin main
875
876report "🟢 ${REPO1_NAME} apex plugin activated"
877echo "# hello" > hello2.md
878echo "## hello2" >> hello2.md
879echo "### hello3" >> hello2.md
880quiet_git add .
881quiet_git commit -m "first html"
882quiet_git push origin main
883
884mySleep 0.1
885
886sed -i -e 's/active: true/active: false/g' .gitroot/plugins.yml
887
888quiet_git add .
889quiet_git commit -m "inactive all plugins"
890quiet_git push origin main
891
892mySleep 0.1
893
894sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
895sed -i -e 's/style: simple.min.css/style: style.css/g' .gitroot/plugins.yml
896
897cp ${SCRIPT_DIR}/../server/resources/styles/simple.min.css style.css
898cat ${SCRIPT_DIR}/../plugins/apex/resources/styles/add.css >> style.css
899echo "body { background-color: 010409 }" >> style.css
900echo "body > header { background-color: 010409; text-align: left; padding: 0 1rem }" >> style.css
901echo "body > header h1 { font-size: 1rem }" >> style.css
902echo "header > nav ul { place-content: normal }" >> style.css
903echo "header > nav a { margin: 0 .5rem; border: 0 }" >> style.css
904
905quiet_git add .
906quiet_git commit -m "perso style"
907quiet_git push origin main
908
909##### User2 can create repo3
910report "🏁 User2 can create repo3 with master branch"
911
912cd /tmp/${ROOT_REPO_NAME}
913sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
914report "🟢 ${ROOT_REPO_NAME} plugins will activate"
915quiet_git add .
916quiet_git commit -m "active all plugins"
917quiet_git push origin main
918
919mySleep 1
920
921quiet_git pull origin main
922report "🟢 ${ROOT_REPO_NAME} plugins activated"
923
924cd /tmp
925GIT_SSH_COMMAND="ssh -i ${SSH_KEY2} -o IdentitiesOnly=yes" quiet_git clone --quiet "${ROOT_REPO_URL}" ${ROOT_REPO_NAME}_2
926cd ${ROOT_REPO_NAME}_2
927quiet_git checkout -b create_repo3
928.gitroot/init.sh --pubKey "${SSH_KEY2}.pub" --privKey "${SSH_KEY2}" --email user2root@gitroot.dev --name user2 >> /tmp/mylog.txt
929PUB=$(cat ${SSH_KEY2}.pub)
930printf "\n${REPO3_NAME}:\n defaultbranch: master\n owners:\n - ${PUB}" >> .gitroot/repositories.yml
931quiet_git add .
932quiet_git commit -m "create repo3"
933quiet_git push origin create_repo3
934report "🟢 ${ROOT_REPO_NAME}_2 push create_repo3 repo"
935
936mySleep 0.1
937
938cd /tmp/${ROOT_REPO_NAME}
939quiet_git pull --rebase origin main
940quiet_git fetch origin create_repo3
941quiet_git checkout create_repo3
942sed -i -e 's/status: draft/status: merge/g' grafts/create_repo3.md
943quiet_git add .
944quiet_git commit -m "merge create_repo3 graft"
945quiet_git push origin create_repo3
946
947mySleep 0.1
948
949cd /tmp
950GIT_SSH_COMMAND="ssh -i ${SSH_KEY2} -o IdentitiesOnly=yes" quiet_git clone --quiet "${REPO3_URL}"
951
952cd ${REPO3_NAME}
953.gitroot/init.sh --pubKey "${SSH_KEY2}.pub" --privKey "${SSH_KEY2}" --email user2repo3@gitroot.dev --name user2 >> /tmp/mylog.txt
954echo "works" > README.md
955quiet_git add .
956quiet_git commit -m "mine readme"
957quiet_git push origin master
958
959##### Shallow
960report "🏁 Shallow"
961
962cd /tmp
963rm -rf repo1_shallow
964GIT_SSH_COMMAND="ssh -i ${SSH_KEY2} -o IdentitiesOnly=yes" quiet_git clone --quiet --depth 1 ssh://git@127.0.0.1:4545/repo1 repo1_shallow
965cd repo1_shallow
966.gitroot/init.sh --pubKey "${SSH_KEY2}.pub" --privKey "${SSH_KEY2}" --email user2repo1Shallow@gitroot.dev --name user2 >> /tmp/mylog.txt
967
968NB_COMMIT=$(git rev-list HEAD --count)
969if [[ $NB_COMMIT -eq 1 ]]; then
970 report "🟢 repo1_shallow has 1 commit"
971else
972 report "🛑 repo1_shallow has $NB_COMMIT commits"
973 EXIT_CODE=1
974fi
975
976quiet_git fetch --deepen 1 origin main
977NB_COMMIT=$(git rev-list HEAD --count)
978if [[ $NB_COMMIT -eq 2 ]]; then
979 report "🟢 repo1_shallow has 2 commits"
980else
981 report "🛑 repo1_shallow has $NB_COMMIT commits"
982 EXIT_CODE=1
983fi
984
985# TODO reactive after go-git v6
986# quiet_git fetch --shallow-exclude=graft_something origin main
987# NB_COMMIT=$(git rev-list HEAD --count)
988# if [[ $NB_COMMIT -eq 11 ]]; then
989# report "🟢 repo1_shallow has 11 commits"
990# else
991# report "🛑 repo1_shallow has $NB_COMMIT commits"
992# EXIT_CODE=1
993# fi
994
995##### Finish
996report "🏁 Finish"
997if grep -q -i "error" /tmp/mylog.txt
998then
999 report "🛑 Logs contains error"
1000 EXIT_CODE=1
1001else
1002 report "🟢 Logs no error"
1003fi
1004
1005if grep -q -i "WARNING: DATA RACE" /tmp/mylog.txt
1006then
1007 report "🛑 Logs contains data race"
1008 EXIT_CODE=1
1009else
1010 report "🟢 Logs no data race"
1011fi
1012
1013report ""
1014report "✎ Find all logs in /tmp/mylog.txt"
1015exit $EXIT_CODE