From: Oleg Broytman Date: Sat, 15 Aug 2020 13:32:04 +0000 (+0300) Subject: Add `copy-scripts/`: Copy this repo to a remote host X-Git-Url: https://git.phdru.name/?p=git-scripts.git;a=commitdiff_plain;h=5e1ae12d726ec5594426315bea7ee6a0b85b8bd1 Add `copy-scripts/`: Copy this repo to a remote host Copy git-scripts to an ssh-accessible remote host. --- diff --git a/copy-scripts/copy-scripts b/copy-scripts/copy-scripts new file mode 100755 index 0000000..2201c0f --- /dev/null +++ b/copy-scripts/copy-scripts @@ -0,0 +1,20 @@ +#!/bin/sh + +# Copy git-scripts to an ssh-accessible remote host; +# setup bare and non-bare repositories and the post-update hook. + +if [ $# -ne 3 ]; then + echo "Usage: $0 [user@]host directory remote_name" >&2 + exit 1 +fi + +remote_host="$1" +remote_dir="$2" +remote_name="$3" + +ssh "$remote_host" "cd $remote_dir && exec git init --bare git-scripts.git" && +git remote add "$remote_name" "$remote_host:$remote_dir/git-scripts.git" && +git push "$remote_name" master && +exec ssh "$remote_host" "cd $remote_dir && git clone git-scripts.git && + cd git-scripts.git/hooks && + exec ln -s ../../git-scripts/copy-scripts/post-update" diff --git a/hooks/post-update b/copy-scripts/post-update similarity index 73% rename from hooks/post-update rename to copy-scripts/post-update index 3350fa8..78fc50d 100755 --- a/hooks/post-update +++ b/copy-scripts/post-update @@ -6,9 +6,7 @@ for ref in "$@"; do if [ "$ref" = refs/heads/master ]; then unset GIT_DIR cd ../git-scripts && - if ! git remote show -n origin 2>/dev/null; then - git remote add origin ../git-scripts.git - fi && + git checkout master && git pull origin master && git push origin master exit