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