From af1543a9a844e362a57dc898088c4f4b068a6675 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 2 Jun 2023 15:05:28 -0500 Subject: Make hook executable and prompt to push --- git-init-remote | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/git-init-remote b/git-init-remote index a934c1f..043a780 100755 --- a/git-init-remote +++ b/git-init-remote @@ -3,8 +3,33 @@ GITREMOTE=git.acdw.net GITROOT=/git +POSTUPDATEHOOK=/tmp/post-update.hook + +init_post_update_hook() { + # This post-update hook will update cgit's date display. + cat <<\EOF +#!/bin/sh + +# Update "agefile" for cgit +# The default location is /info/web/last-modified +agefile="$(git rev-parse --git-dir)/info/web/last-modified" +mkdir -p "$(dirname "$agefile")" + +git for-each-ref > "$agefile" \ + --sort=-authordate --count=1 \ + --format='%(authordate:iso8601)' + +# Prepare a packed repository for use over dumb transports +git update-server-info +EOF +} + +## Setup + git ls-files > /dev/null || exit 1 +test -f "$POSTUPDATEHOOK" || init_post_update_hook > "$POSTUPDATEHOOK" + # consider --git-dir as well .. however --git-dir would require more massaging # of the output. local="$(git rev-parse --show-toplevel)" @@ -23,10 +48,23 @@ echo "ssh \"$GITREMOTE\" ed \"$remote/description\"" ssh "$GITREMOTE" ed "$remote/description" # Add post-update-hook -echo "scp post-update.hook \"$GITREMOTE:$remote/hooks/post-update\"" -scp post-update.hook "$GITREMOTE:$remote/hooks/post-update" +echo "scp \"$POSTUPDATEHOOK\" \"$GITREMOTE:$remote/hooks/post-update\"" +scp "$POSTUPDATEHOOK" "$GITREMOTE:$remote/hooks/post-update" +echo "ssh \"$GITREMOTE\" chmod +x \"$remote/hooks/post-update\"" +ssh "$GITREMOTE" chmod +x "$remote/hooks/post-update" ## Local work echo "git remote add origin \"$GITREMOTE:$remote\"" git remote add origin "$GITREMOTE:$remote" + +echo -n "Push to remote?" +read + +case "$REPLY" in + y*|Y*|'') + echo git push -u origin main + git push -u origin main + ;; + *) ;; +esac -- cgit 1.4.1-21-gabe81