add-repo (1009B)
1 #!/bin/sh 2 # Create a bare repo with hook + metadata. 3 # Usage: add-repo <name> [--public] [-d "description"] 4 set -eu 5 6 . "$HOME/repos/config.env" 2>/dev/null || true 7 : "${GIT_HOSTNAME:=$(hostname)}" 8 : "${PUBLIC_DOMAIN:=git.example.com}" 9 10 name="" 11 public=0 12 desc="" 13 while [ $# -gt 0 ]; do 14 case $1 in 15 --public) public=1 ;; 16 -d) desc=$2; shift ;; 17 -*) echo "unknown flag: $1" >&2; exit 2 ;; 18 *) name=$1 ;; 19 esac 20 shift 21 done 22 [ -n "$name" ] || { echo "usage: add-repo <name> [--public] [-d desc]" >&2; exit 2; } 23 24 dir=$HOME/repos/$name.git 25 [ -e "$dir" ] && { echo "already exists: $dir" >&2; exit 1; } 26 27 git init --bare "$dir" 28 ln -s "$HOME/repos/bin/post-receive" "$dir/hooks/post-receive" 29 echo "${desc:-$name}" > "$dir/description" 30 31 if [ "$public" = "1" ]; then 32 touch "$dir/public" 33 echo "https://$PUBLIC_DOMAIN/git/$name.git" > "$dir/url" 34 else 35 echo "ssh://$USER@$GIT_HOSTNAME/~/repos/$name.git" > "$dir/url" 36 fi 37 38 "$HOME/repos/bin/stagit-update" "$name" 39 echo "ok: $dir"