feat: downstream command maybe?

This commit is contained in:
əlemi 2024-02-08 21:48:38 +01:00
parent 9b7462b45f
commit aeb09e169a
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 30 additions and 0 deletions

29
downstream Executable file
View file

@ -0,0 +1,29 @@
#!/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"

1
help
View file

@ -5,6 +5,7 @@ echo " $ ls list all repositories, marks hidden
echo " $ new <name> create new repository"
echo " $ mirror <url> [name] mirror remote repository"
echo " $ upstream <repo> <url> set repository to push to a given remote"
echo " $ downstream <repo> <url> set repository to fetch from a given remote"
echo " $ sync push and pull all mirrored repositories"
echo " $ tree <repo> show file tree of repo at HEAD"
echo " $ log <repo> show commit log of repo"