commit ee29a2a5f393d1396a2445d150cf6d837c8b86cc
parent 574532787a9a7fba1ce8174d418f997d35cec8f9
Author: Fred Großkopf <fred@kuandu.systems>
Date: Wed, 15 Apr 2026 15:17:18 +0200
Bug Fix gitpages.sh
When in single repo mode,
do not delete other repos.
Diffstat:
2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/gitpages.sh b/gitpages.sh
@@ -193,9 +193,6 @@ main() {
[ -z "$CONFIG_FILE" ] && CONFIG_FILE="$(dirname "$0")/${CONFIG_FILE_NAME}"
load_config "$CONFIG_FILE"
- # Clear destination (safety-checKed earlier)
- # shellcheck disable=SC2115 # wants non-posix compatible ${var:?}
- [ "$DST_DIR" != "/" ] && rm -rf "$DST_DIR"/*
# Unified repo processing
if [ -n "$SINGLE_REPO" ]; then
@@ -206,6 +203,10 @@ main() {
generate_index
info "Generated single repo: $repo → $DST_DIR"
else
+ # Clear destination (safety-checked earlier)
+ # shellcheck disable=SC2115 # wants non-posix compatible ${var:?}
+ [ "$DST_DIR" != "/" ] && rm -rf "$DST_DIR"/*
+
for repo in "$SRC_DIR"/*.git; do
[ -e "$repo" ] || continue
is_git_repo "$repo" || {
diff --git a/test-gitpages.sh b/test-gitpages.sh
@@ -309,6 +309,30 @@ test_index_rewriting() {
fi
}
+test_single_repo_does_not_remove_others() {
+ printf '=== Test 12: Single repo does not remove other repos ===\\n'
+
+ # 1. Create two repos and do a full sync
+ mkdir -p "$RAW_SRC/repo1.git" "$RAW_SRC/repo2.git"
+ (cd "$RAW_SRC/repo1.git" && git init --bare > /dev/null 2>&1)
+ (cd "$RAW_SRC/repo2.git" && git init --bare > /dev/null 2>&1)
+
+ "$SCRIPT_NAME" "$RAW_SRC" "$HTML_DST" > /dev/null 2>&1 \
+ || error "$SCRIPT_NAME failed for full sync (before single‑repo test)"
+
+ check_dir_exists "$HTML_DST/repo1" "repo1 HTML generated (before single run)"
+ check_dir_exists "$HTML_DST/repo2" "repo2 HTML generated (before single run)"
+
+ # 2. Now run in single‑repo mode for repo1.git only
+ "$SCRIPT_NAME" "$RAW_SRC/repo1.git" "$HTML_DST" > /dev/null 2>&1 \
+ || error "$SCRIPT_NAME failed for single repo (repo1.git)"
+
+ # 3. Verify neither repo1 nor repo2 HTML dirs get deleted
+ check_dir_exists "$HTML_DST/repo1" "repo1 HTML still present after single‑repo run"
+ check_dir_exists "$HTML_DST/repo2" "repo2 HTML still present after single‑repo
+run"
+}
+
main() {
printf 'Testing %s\n' "$SCRIPT_NAME"
check_script
@@ -327,6 +351,7 @@ main() {
test_repo_titles_without_rewriting
test_repo_titles_rewriting
test_index_rewriting
+ test_single_repo_does_not_remove_others
printf '\nALL TESTS PASSED!\n'
printf 'Test environment cleaned up.\n'