From aeb09e169ac585d35b2b84709c0baa0de1072c4d Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 8 Feb 2024 21:48:38 +0100 Subject: [PATCH] feat: downstream command maybe? --- downstream | 29 +++++++++++++++++++++++++++++ help | 1 + 2 files changed, 30 insertions(+) create mode 100755 downstream diff --git a/downstream b/downstream new file mode 100755 index 0000000..4389535 --- /dev/null +++ b/downstream @@ -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" diff --git a/help b/help index 5b987ba..dd08080 100755 --- a/help +++ b/help @@ -5,6 +5,7 @@ echo " $ ls list all repositories, marks hidden echo " $ new create new repository" echo " $ mirror [name] mirror remote repository" echo " $ upstream set repository to push to a given remote" +echo " $ downstream set repository to fetch from a given remote" echo " $ sync push and pull all mirrored repositories" echo " $ tree show file tree of repo at HEAD" echo " $ log show commit log of repo"