2022-04-26 11:26:22 +00:00
|
|
|
#!/bin/bash -e
|
2021-06-19 19:24:14 +00:00
|
|
|
# Clones a fork and sets a corresponding upstream
|
2021-10-11 08:02:14 +00:00
|
|
|
# ARGS
|
2022-01-11 12:23:56 +00:00
|
|
|
# - repo name (omit if setting upstream in existing repo)
|
2021-06-19 19:24:14 +00:00
|
|
|
# - upstream user
|
2022-04-26 11:26:22 +00:00
|
|
|
# - own user
|
2022-05-03 16:26:15 +00:00
|
|
|
# - host
|
2021-10-08 10:31:00 +00:00
|
|
|
# - target directory name (and further arguments to clone)
|
2022-04-26 11:26:22 +00:00
|
|
|
# In an existing repo, first arg is omitted
|
2024-02-20 18:54:51 +00:00
|
|
|
# TODO: transform https://codeberg.org/forgejo-contrib/forgejo-helm -> forgejo-helm forgejo-contrib "" codeberg.org
|
2023-01-31 18:10:27 +00:00
|
|
|
if test -d ".git" # TODO search upwards
|
2022-01-11 12:23:56 +00:00
|
|
|
then repo="$(basename "$PWD")"
|
2023-01-31 18:10:27 +00:00
|
|
|
git remote set-url origin "$(git-repo "${3:-github.com}" "$repo" "${2:-$(git config --get user.name)}" "${@:4}")"
|
2024-02-20 18:54:51 +00:00
|
|
|
git remote remove upstream 2>/dev/null || true
|
|
|
|
else test $# -eq 0 && echo "Usage: $0 <repo (omit if in repo)> <upstream owner> [own user] [host]" && exit 2
|
2023-01-31 18:10:27 +00:00
|
|
|
repo="$1" && shift
|
|
|
|
if test "$#" -eq 0
|
|
|
|
then git-get "$repo"
|
|
|
|
else
|
|
|
|
test -d "$d1" && cd "$d1/0-forks"
|
|
|
|
if ! git-get "${3:-github.com}" "$repo" "${2:-$(git config --get user.name)}" "${@:4}"
|
|
|
|
then repo="$1-$repo"
|
|
|
|
git-get "${3:-github.com}" "$repo" "${2:-$(git config --get user.name)}" "${@:4}"
|
|
|
|
fi
|
2022-07-03 20:33:28 +00:00
|
|
|
fi
|
2023-01-31 18:10:27 +00:00
|
|
|
cd "$(basename "$(expr "$4" \| "$repo")")"
|
2021-10-31 19:21:35 +00:00
|
|
|
fi
|
2022-01-16 13:14:17 +00:00
|
|
|
user="${1:-$repo}"
|
2024-02-20 18:54:51 +00:00
|
|
|
git-upstream "$user"
|
|
|
|
#git remote add upstream "$(git-repo "${3:-github.com}" "$repo" "$user")"
|
2022-10-13 19:57:22 +00:00
|
|
|
exec $SHELL
|