From 5d6305bf86684376e7b0fa885f64edf0997a109b Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Sun, 31 Oct 2021 20:21:35 +0100 Subject: [PATCH] config/git: update existing repos with git-fork --- .local/bin/scripts/git-aur | 2 +- .local/bin/scripts/git-fork | 10 ++++++---- .local/bin/scripts/git-repo | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.local/bin/scripts/git-aur b/.local/bin/scripts/git-aur index c3045f4..a95be3c 100755 --- a/.local/bin/scripts/git-aur +++ b/.local/bin/scripts/git-aur @@ -21,7 +21,7 @@ case $command in git aur push --amend;; (push) makepkg --printsrcinfo > .SRCINFO - git add -f .SRCINFO *.install + git add -f .SRCINFO *.install >/dev/null || true git commit -v -a "$@" git push;; esac diff --git a/.local/bin/scripts/git-fork b/.local/bin/scripts/git-fork index 7c2edb3..7dbb1df 100755 --- a/.local/bin/scripts/git-fork +++ b/.local/bin/scripts/git-fork @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/sh -e # Clones a fork and sets a corresponding upstream # ARGS # - repo name @@ -6,8 +6,10 @@ # - local user # - url # - target directory name (and further arguments to clone) -set -e -git-get "${4:-github.com}" "$1" "$3" "${@:5}" -cd $(expr "$5" \| "$1") +if test -d ".git" + then git remote set-url origin "$(git-repo "${4:-github.com}" "$1" "$3" "${@:5}")" + else git-get "${4:-github.com}" "$1" "$3" "${@:5}" + cd $(expr "$5" \| "$1") +fi test "$2" && git remote add upstream "$(git-repo "${4:-github.com}" "$1" "$2")" git remote -v diff --git a/.local/bin/scripts/git-repo b/.local/bin/scripts/git-repo index 2512d2c..2416479 100755 --- a/.local/bin/scripts/git-repo +++ b/.local/bin/scripts/git-repo @@ -1,7 +1,7 @@ #!/bin/sh # Translates different repo notations into ssh case "$1" in -http*) echo "git@$(echo "$1" | cut -d'/' -f3):$(echo "$1" | cut -d'/' -f4)/$(echo "$1" | cut -d'/' -f5)" ;; -git:*) echo "$1" ;; -*) echo "${1:-git.jfischer.org}:${3:-$(git config user.name)}/${2:-$(basename $PWD)}.git" ;; + (http*) echo $1 | sed "s|.*//\([^/]*\)/\(.*\)|git@\1:\2.git|";; + (git:*) echo "$1" ;; + (*) echo "${1:-git.jfischer.org}:${3:-$(git config user.name)}/${2:-$(basename $PWD)}.git" ;; esac