gitshell/mirror
alemi 6bdae48354 feat: pushing existing commands
i made this some time ago, pushing as one commit
2024-01-12 09:46:11 +01:00

30 lines
676 B
Bash
Executable file

#!/bin/bash
if [ $# -eq 0 ]; then
echo "[!] no repository specified"
exit
fi
REMOTE="origin" # TODO can we get this as argument but optionally?
if [ $# -eq 1 ]; then
IFS='/' read -ra FRAGS <<< "$1"
REPOSITORY=${FRAGS[-1]}
REPONAME=${FRAGS[-1]}
else
REPOSITORY="$2" # with .git
REPONAME="$2" # without .git
fi
if [[ ! "$REPOSITORY" == *.git ]]; then
REPOSITORY="$REPOSITORY.git"
fi
if [[ "$REPONAME" == *.git ]]; then
REPONAME=$(echo "$REPONAME" | sed 's/\.git$//')
fi
git clone --mirror "$1" "/srv/git/$REPOSITORY" --origin "$REMOTE"
git config -f "/srv/git/$REPOSITORY/config" "remote.$REMOTE.direction" "down"
cd "$REPOSITORY"
/srv/git/.hooks/post-receive