diff --git a/cgi/pages/publish.sh b/cgi/pages/publish.sh index 790d081499..1678a12bb2 100755 --- a/cgi/pages/publish.sh +++ b/cgi/pages/publish.sh @@ -58,7 +58,12 @@ parent=$(basename "$(dirname "$repo")") tmp="" lock="" +uuid="" cleanup() { + if [ -n "$uuid" ] && [ -n "${repo:-}" ]; then + got ref -d -r "$repo" \ + "refs/got/worktree/base-$uuid" >/dev/null 2>&1 || true + fi [ -n "$tmp" ] && rm -rf "$tmp" [ -n "$lock" ] && rmdir "$lock" 2>/dev/null || true } @@ -78,6 +83,7 @@ wt="$tmp/wt" got checkout -q -b "$branch" "$repo" "$wt" || die "got checkout of $branch failed" +uuid=$(cat "$wt/.got/uuid" 2>/dev/null || true) actual=$(cd "$wt" && got log -l 1 | awk '/^commit /{print $2; exit}') if [ "$actual" != "$rev" ]; then (cd "$wt" && got update -q -c "$rev") || diff --git a/cgi/tests/run.sh b/cgi/tests/run.sh index c706376d35..39166d539e 100755 --- a/cgi/tests/run.sh +++ b/cgi/tests/run.sh @@ -149,6 +149,8 @@ git clone -q --bare . "$tmp/repos/owner/site.git" bb_rev=$(git rev-parse pages) mkdir -p "$tmp/pages" printf 'owner/site\n' > "$tmp/allow" +refs_before=$(got ref -l -r "$tmp/repos/owner/site.git" | + grep -c 'refs/got/worktree' || true) GOTEA_PAGES_ROOT="$tmp/pages" GOTEA_BB="$bb" \ "$cgi/pages/publish.sh" "$tmp/repos/owner/site.git" owner/site \ @@ -157,6 +159,10 @@ GOTEA_PAGES_ROOT="$tmp/pages" GOTEA_BB="$bb" \ fail "publish: no index.html" expect_contains "$(cat "$tmp/pages/owner/site/index.html")" \ ' $refs_after)" echo "PASS publish" pages_run() { @@ -212,6 +218,10 @@ hookout=$(printf '%040d %s refs/heads/pages\n' 0 "$bb_rev" | env -i PATH=/usr/bin:/bin GIT_DIR="$tmp/repos/owner/site.git" \ "$tmp/repos/owner/site.git/hooks/post-receive.d/gotea-pages" 2>&1) expect_contains "$hookout" "published owner/site" "hook: publish output" +refs_hook=$(got ref -l -r "$tmp/repos/owner/site.git" | + grep -c 'refs/got/worktree' || true) +[ "$refs_before" = "$refs_hook" ] || + fail "hook: worktree ref leaked ($refs_before -> $refs_hook)" echo "PASS post-receive hook" echo "all gotea-cgi tests passed"