52 lines
1.1 KiB
Bash
Executable File
52 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
git-setup-upstream(){
|
|
|
|
if [[ $# -ne 0 ]]; then
|
|
echo "Usage: just run inside a bbgithub repo."
|
|
return
|
|
fi
|
|
|
|
st=$(git status)
|
|
if [[ $? -ne 0 ]]; then
|
|
echo "Looks this is not a git repo."
|
|
return
|
|
fi
|
|
|
|
us=$(git remote get-url upstream 2> /dev/null)
|
|
if [[ $? -eq 0 ]]; then
|
|
echo "Upstream already exist as $us."
|
|
return
|
|
fi
|
|
|
|
url=$(git remote get-url origin)
|
|
if [[ $? -ne 0 ]]; then
|
|
echo "Origin URL is unknown."
|
|
return
|
|
fi
|
|
|
|
re="^(.*)[/:]([^/:]*)/(.*)$"
|
|
if [[ $url =~ $re ]]; then
|
|
prefix=${BASH_REMATCH[1]}
|
|
org=${BASH_REMATCH[2]}
|
|
repo=${BASH_REMATCH[3]}
|
|
else
|
|
echo "Failed to pars the repo URL."
|
|
return
|
|
fi
|
|
|
|
upstream_repo=bbgithub:$org/$repo
|
|
origin_repo=bbgithub:vkhachatrya5/$repo
|
|
|
|
git remote rm origin
|
|
echo "Setting origin=$origin_repo"
|
|
git remote add origin $origin_repo
|
|
echo "Setting upstream=$upstream_repo"
|
|
git remote add upstream $upstream_repo
|
|
git remote -v
|
|
}
|
|
|
|
git-setup-upstream
|
|
|
|
|