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

commit ce0a3b3cb4f41d0970d8656891a503736f261650
parent 764401c7ea747b9cb8ae6b223b7cd88090797b2d
Author: Fred Großkopf <fred@kuandu.systems>
Date:   Wed, 29 Apr 2026 00:07:10 +0200

Renames mirror-git to gitpages-mirror-git

Diffstat:
Mgitpages-init.sh | 2+-
Rmirror-git.sh -> gitpages-mirror-git.sh | 0
Mgitpages-update.sh | 2+-
Mtest-gitpages-init.sh | 2+-
Atest-gitpages-mirror-git.sh | 142+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtest-gitpages-update.sh | 2+-
Dtest-mirror-git.sh | 142-------------------------------------------------------------------------------
7 files changed, 146 insertions(+), 146 deletions(-)

diff --git a/gitpages-init.sh b/gitpages-init.sh @@ -36,7 +36,7 @@ main() { [ -d "$GIT_RAW" ] || error "GIT_RAW directory $GIT_RAW does not exist" printf 'info: 1/2 Mirroring repos %s → %s\n' "$GIT_SRC" "$GIT_RAW" - mirror-git.sh "$GIT_SRC" "$GIT_RAW" || error "Mirroring failed" + gitpages-mirror-git.sh "$GIT_SRC" "$GIT_RAW" || error "Mirroring failed" printf 'info: 2/2 Generating HTML for all repos in %s\n' "$GIT_RAW" diff --git a/mirror-git.sh b/gitpages-mirror-git.sh diff --git a/gitpages-update.sh b/gitpages-update.sh @@ -25,7 +25,7 @@ process_repo() { repo_name=$(basename "$repo_path") GIT_RAW=$(get_config_val "$config_file" "GIT_RAW") - if ! mirror-git.sh "$repo_path" "$GIT_RAW/$repo_name"; then + if ! gitpages-mirror-git.sh "$repo_path" "$GIT_RAW/$repo_name"; then error "Failed to mirror $repo_name" return 1 fi diff --git a/test-gitpages-init.sh b/test-gitpages-init.sh @@ -23,7 +23,7 @@ EOF } # Generate mocks -mock_bin mirror-git.sh +mock_bin gitpages-mirror-git.sh mock_bin gitpages.sh mock_bin git mock_bin stagit diff --git a/test-gitpages-mirror-git.sh b/test-gitpages-mirror-git.sh @@ -0,0 +1,142 @@ +#!/bin/sh + +set -eu + +SCRIPT_NAME="./gitpages-mirror-git.sh" + +check_script() { + if [ ! -x "$SCRIPT_NAME" ]; then + printf 'ERROR: %s not found or not executable\n' "$SCRIPT_NAME" >&2 + printf 'Please run:\n chmod +x git-sync.sh\n ./test-git-sync.sh\n' >&2 + exit 1 + fi +} + +TEST_BASE="" +cleanup() { + [ -n "$TEST_BASE" ] && rm -rf "$TEST_BASE" +} +trap cleanup EXIT INT TERM + +error() { + printf 'FAIL: %s\n' "$1" >&2 + exit 1 +} + +success() { + printf 'PASS: %s\n' "$1" +} + +setup() { + TEST_BASE=$(mktemp -d) || error "Failed to create temp dir" + SRC_DIR="$TEST_BASE/src" + DST_DIR="$TEST_BASE/dst" + mkdir -p "$SRC_DIR" "$DST_DIR" +} + +assert_fails() { + test_num="$1" + test_desc="$2" + shift 2 + printf '=== Test %s: %s ===\n' "$test_num" "$test_desc" + "$@" && error "Should fail" || success "Rejects $test_desc" +} + +assert_repo_copied() { + repo="$1" + test_name="$2" + [ -d "$repo" ] && success "$test_name" || error "$test_name" +} + +assert_repo_skipped() { + repo="$1" + test_name="$2" + [ ! -d "$repo" ] && success "$test_name" || error "$test_name" +} + +assert_bare_repo() { + repo="$1" + test_name="$2" + git --git-dir="$repo" rev-parse --is-bare-repository >/dev/null 2>&1 || error "$test_name" +} + +assert_server_info() { + repo="$1" + test_name="$2" + [ -f "$repo/info/refs" ] && success "$test_name" || error "$test_name" +} + +test_args() { + assert_fails 1 "Wrong number of arguments" "$SCRIPT_NAME" "$SRC_DIR" "$DST_DIR" extra_arg +} + +test_bad_src_file() { + bad_src="$TEST_BASE/bad_src" + touch "$bad_src" + assert_fails 2 "Source is file" "$SCRIPT_NAME" "$bad_src" "$DST_DIR" +} + +test_bad_dst() { + bad_dst="$TEST_BASE/bad_dst" + touch "$bad_dst" && chmod 444 "$bad_dst" + assert_fails 3 "Destination not writable" "$SCRIPT_NAME" "$SRC_DIR" "$bad_dst" +} + +test_empty_src() { + rm -rf "$SRC_DIR"/* + assert_fails 4 "Empty source directory" "$SCRIPT_NAME" "$SRC_DIR" "$DST_DIR" +} + +test_full_sync() { + printf '=== Test 5: Full sync ===\n' + mkdir -p "$SRC_DIR/myrepo.git" "$SRC_DIR/otherrepo" + (cd "$SRC_DIR/myrepo.git" && git init --bare . >/dev/null 2>&1) + (cd "$SRC_DIR/otherrepo" && git init >/dev/null 2>&1) + + "$SCRIPT_NAME" "$SRC_DIR" "$DST_DIR" + + assert_repo_copied "$DST_DIR/myrepo.git" "Bare repo copied" + assert_repo_skipped "$DST_DIR/otherrepo" "Skipped non-bare" + assert_bare_repo "$DST_DIR/myrepo.git" "Destination is bare" + assert_server_info "$DST_DIR/myrepo.git" "update-server-info ran" +} + +test_single_repo() { + printf '=== Test 6: Single repo ===\n' + mkdir -p "$SRC_DIR/myrepo.git" + (cd "$SRC_DIR/myrepo.git" && git init --bare . >/dev/null 2>&1) + + "$SCRIPT_NAME" "$SRC_DIR/myrepo.git" "$DST_DIR" + + assert_repo_copied "$DST_DIR/myrepo.git" "Single repo copied" + assert_bare_repo "$DST_DIR/myrepo.git" "Single mode: bare repo" + assert_server_info "$DST_DIR/myrepo.git" "Single mode: update-server-info ran" +} + +test_root_protection() { + assert_fails 7 "Root protection" "$SCRIPT_NAME" "$SRC_DIR" "/" +} + +test_non_repo_dir() { + assert_fails 8 "Non-repo directory" "$SCRIPT_NAME" "$TEST_BASE" "$DST_DIR" +} + +main() { + printf 'Testing %s\n' "$SCRIPT_NAME" + check_script + setup + + test_args + test_bad_src_file + test_bad_dst + test_empty_src + test_full_sync + test_single_repo + test_root_protection + test_non_repo_dir + + printf '\nALL TESTS PASSED!\n' + printf 'Test environment cleaned up.\n' +} + +[ "${0##*/}" = "test-gitpages-mirror-git.sh" ] && main "$@" diff --git a/test-gitpages-update.sh b/test-gitpages-update.sh @@ -23,7 +23,7 @@ EOF chmod +x "$TEST_DIR/bin/$1" } -mock_bin mirror-git.sh +mock_bin gitpages-mirror-git.sh mock_bin gitpages.sh # Setup test environment diff --git a/test-mirror-git.sh b/test-mirror-git.sh @@ -1,142 +0,0 @@ -#!/bin/sh - -set -eu - -SCRIPT_NAME="./mirror-git.sh" - -check_script() { - if [ ! -x "$SCRIPT_NAME" ]; then - printf 'ERROR: %s not found or not executable\n' "$SCRIPT_NAME" >&2 - printf 'Please run:\n chmod +x git-sync.sh\n ./test-git-sync.sh\n' >&2 - exit 1 - fi -} - -TEST_BASE="" -cleanup() { - [ -n "$TEST_BASE" ] && rm -rf "$TEST_BASE" -} -trap cleanup EXIT INT TERM - -error() { - printf 'FAIL: %s\n' "$1" >&2 - exit 1 -} - -success() { - printf 'PASS: %s\n' "$1" -} - -setup() { - TEST_BASE=$(mktemp -d) || error "Failed to create temp dir" - SRC_DIR="$TEST_BASE/src" - DST_DIR="$TEST_BASE/dst" - mkdir -p "$SRC_DIR" "$DST_DIR" -} - -assert_fails() { - test_num="$1" - test_desc="$2" - shift 2 - printf '=== Test %s: %s ===\n' "$test_num" "$test_desc" - "$@" && error "Should fail" || success "Rejects $test_desc" -} - -assert_repo_copied() { - repo="$1" - test_name="$2" - [ -d "$repo" ] && success "$test_name" || error "$test_name" -} - -assert_repo_skipped() { - repo="$1" - test_name="$2" - [ ! -d "$repo" ] && success "$test_name" || error "$test_name" -} - -assert_bare_repo() { - repo="$1" - test_name="$2" - git --git-dir="$repo" rev-parse --is-bare-repository >/dev/null 2>&1 || error "$test_name" -} - -assert_server_info() { - repo="$1" - test_name="$2" - [ -f "$repo/info/refs" ] && success "$test_name" || error "$test_name" -} - -test_args() { - assert_fails 1 "Wrong number of arguments" "$SCRIPT_NAME" "$SRC_DIR" "$DST_DIR" extra_arg -} - -test_bad_src_file() { - bad_src="$TEST_BASE/bad_src" - touch "$bad_src" - assert_fails 2 "Source is file" "$SCRIPT_NAME" "$bad_src" "$DST_DIR" -} - -test_bad_dst() { - bad_dst="$TEST_BASE/bad_dst" - touch "$bad_dst" && chmod 444 "$bad_dst" - assert_fails 3 "Destination not writable" "$SCRIPT_NAME" "$SRC_DIR" "$bad_dst" -} - -test_empty_src() { - rm -rf "$SRC_DIR"/* - assert_fails 4 "Empty source directory" "$SCRIPT_NAME" "$SRC_DIR" "$DST_DIR" -} - -test_full_sync() { - printf '=== Test 5: Full sync ===\n' - mkdir -p "$SRC_DIR/myrepo.git" "$SRC_DIR/otherrepo" - (cd "$SRC_DIR/myrepo.git" && git init --bare . >/dev/null 2>&1) - (cd "$SRC_DIR/otherrepo" && git init >/dev/null 2>&1) - - "$SCRIPT_NAME" "$SRC_DIR" "$DST_DIR" - - assert_repo_copied "$DST_DIR/myrepo.git" "Bare repo copied" - assert_repo_skipped "$DST_DIR/otherrepo" "Skipped non-bare" - assert_bare_repo "$DST_DIR/myrepo.git" "Destination is bare" - assert_server_info "$DST_DIR/myrepo.git" "update-server-info ran" -} - -test_single_repo() { - printf '=== Test 6: Single repo ===\n' - mkdir -p "$SRC_DIR/myrepo.git" - (cd "$SRC_DIR/myrepo.git" && git init --bare . >/dev/null 2>&1) - - "$SCRIPT_NAME" "$SRC_DIR/myrepo.git" "$DST_DIR" - - assert_repo_copied "$DST_DIR/myrepo.git" "Single repo copied" - assert_bare_repo "$DST_DIR/myrepo.git" "Single mode: bare repo" - assert_server_info "$DST_DIR/myrepo.git" "Single mode: update-server-info ran" -} - -test_root_protection() { - assert_fails 7 "Root protection" "$SCRIPT_NAME" "$SRC_DIR" "/" -} - -test_non_repo_dir() { - assert_fails 8 "Non-repo directory" "$SCRIPT_NAME" "$TEST_BASE" "$DST_DIR" -} - -main() { - printf 'Testing %s\n' "$SCRIPT_NAME" - check_script - setup - - test_args - test_bad_src_file - test_bad_dst - test_empty_src - test_full_sync - test_single_repo - test_root_protection - test_non_repo_dir - - printf '\nALL TESTS PASSED!\n' - printf 'Test environment cleaned up.\n' -} - -[ "${0##*/}" = "test-mirror-git.sh" ] && main "$@"