gitpages

A collection of scripts to securely webhost and publish git repositories.
git clone https://scm.kuandu.systems/git-raw/gitpages.git
Log | Files | Refs | README | LICENSE

test-gitpages-init-repos.sh (2635B)


      1 #!/bin/sh
      2 #
      3 # Copyright (c) 2026 Fred Großkopf
      4 #
      5 # Permission to use, copy, modify, and/or distribute this software for any
      6 # purpose with or without fee is hereby granted, provided that the above
      7 # copyright notice and this permission notice appear in all copies.
      8 #
      9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     16 
     17 set -eu
     18 
     19 WORKDIR=""
     20 TARGET=""
     21 
     22 log() { printf 'test: %s\n' "$1"; }
     23 die() { printf 'test: error: %s\n' "$1" >&2; exit 1; }
     24 
     25 setup_dirs() {
     26   WORKDIR="$(mktemp -d -t gitpages_test.XXXXXX)" ||
     27     die "mktemp failed"
     28 
     29   TARGET="$WORKDIR/repos"
     30   mkdir "$TARGET"
     31 
     32   # Quiet git default‑branch hint
     33   GIT_CONFIG_NOSYSTEM=1 \
     34     git config --global init.defaultBranch main
     35 
     36   log "created test workspace in $WORKDIR"
     37 }
     38 
     39 setup_repos() {
     40   git init --bare "$TARGET/foo.git"
     41   git init --bare "$TARGET/bar.git"
     42   log "created foo.git and bar.git"
     43 }
     44 
     45 run_gitpages_init() {
     46   log "running gitpages-init-repos.sh"
     47 
     48   # Feed 3 lines per repo: desc, owner, url
     49   (
     50     printf '%s\n' "Description for foo"
     51     printf '%s\n' "user@foo.org"
     52     printf '%s\n' "https://foo.example.com"
     53 
     54     printf '%s\n' "Description for bar"
     55     printf '%s\n' "user@bar.org"
     56     printf '%s\n' "https://bar.example.com"
     57   ) | ./gitpages-init-repos.sh "$TARGET"
     58 }
     59 
     60 inspect_repos() {
     61   log "contents of repos:"
     62   for repo in "$TARGET"/*.git; do
     63     if [ -d "$repo" ]; then
     64       repo_name=$(basename "$repo" .git)
     65       printf '\n== %s ==\n' "$repo_name"
     66 
     67       if [ -f "$repo/description" ]; then
     68         printf 'desc:\n'; cat "$repo/description"
     69       else
     70         printf 'desc: (MISSING!)\n'
     71       fi
     72 
     73       if [ -f "$repo/owner" ]; then
     74         printf '\nowner:\n'; cat "$repo/owner"
     75       else
     76         printf 'owner: (MISSING!)\n'
     77       fi
     78 
     79       if [ -f "$repo/url" ]; then
     80         printf '\nurl:\n'; cat "$repo/url"
     81       else
     82         printf 'url: (MISSING!)\n'
     83       fi
     84 
     85       hook="$repo/hooks/post-receive"
     86       if [ -f "$hook" ]; then
     87         printf '\npost-receive (head 10):\n'; head -10 "$hook"
     88       else
     89         printf 'post-receive hook: (MISSING!)\n'
     90       fi
     91     fi
     92   done
     93 }
     94 
     95 main() {
     96   setup_dirs
     97   setup_repos
     98   run_gitpages_init
     99   inspect_repos
    100 
    101   log "test complete"
    102 }
    103 
    104 main