mirror of
https://git.alemi.dev/gitshell.git
synced 2024-11-22 15:34:52 +01:00
30 lines
646 B
Text
30 lines
646 B
Text
|
#!/bin/bash
|
||
|
if [ $# -lt 2 ]; then
|
||
|
echo "[!] must specify both repository and remote"
|
||
|
exit
|
||
|
fi
|
||
|
|
||
|
REPOSITORY="$1"
|
||
|
URL="$2"
|
||
|
|
||
|
if [[ ! "$REPOSITORY" == *.git ]]; then
|
||
|
REPOSITORY="$REPOSITORY.git"
|
||
|
fi
|
||
|
|
||
|
if [ ! -d "/srv/git/$REPOSITORY" ]; then
|
||
|
echo "[!] repository does not exist"
|
||
|
exit
|
||
|
fi
|
||
|
|
||
|
REMOTE="origin"
|
||
|
if [[ $# -eq 3 ]]; then
|
||
|
REMOTE="$3"
|
||
|
fi
|
||
|
|
||
|
cd "/srv/git/$REPOSITORY"
|
||
|
|
||
|
git remote remove "$REMOTE" # TODO this complains about branches abandoned, but we will recreate the remote right after this, so maybe do it smartly and check?
|
||
|
git remote add "$REMOTE" "$URL"
|
||
|
git config remote.$REMOTE.mirror "true"
|
||
|
git config remote.$REMOTE.direction "down"
|