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