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

22 lines
760 B
Bash
Executable File

#!/bin/bash -e
# Clones a fork and sets a corresponding upstream
# ARGS
# - repo name (omit if setting upstream in existing repo)
# - upstream user
# - own user
# - host
# - 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"
then repo="$(basename "$PWD")"
git remote set-url origin "$(git-repo "${3:-github.com}" "$repo" "$2" "${@:4}")"
else repo="$1" && shift
git-get "${3:-github.com}" "$repo" "${2:-$(git config --get user.name)}" "${@:4}"
cd "$(expr "$4" \| "$repo")"
fi
user="${1:-$repo}"
git remote add upstream "$(git-repo "${3:-github.com}" "$repo" "$user")"
git remote -v