dotfiles/.local/bin/scripts/git-fork

22 lines
759 B
Plaintext
Raw Normal View History

#!/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
# - own user
2021-10-11 08:02:14 +00:00
# - url
2021-10-08 10:31:00 +00:00
# - target directory name (and further arguments to clone)
# In an existing repo, first arg is omitted
test $# -eq 0 && echo "Usage: $0 [repo] [upstream owner] [own user] [url]" && exit 2
# TODO check from subdir
if test -d ".git"
2022-01-11 12:23:56 +00:00
then repo="$(basename "$PWD")"
git remote set-url origin "$(git-repo "${3:-github.com}" "$repo" "$2" "${@:4}")"
2022-01-12 11:44:28 +00:00
else repo="$1" && shift
git-get "${3:-github.com}" "$repo" "${2:-$(git config --get user.name)}" "${@:4}"
cd "$(expr "$4" \| "$repo")"
fi
2022-01-16 13:14:17 +00:00
user="${1:-$repo}"
git remote add upstream "$(git-repo "${3:-github.com}" "$repo" "$user")"
2021-06-19 19:24:14 +00:00
git remote -v