diff --git a/config/.gitconfig b/config/.gitconfig index 05d245b..887c5c3 100644 --- a/config/.gitconfig +++ b/config/.gitconfig @@ -17,6 +17,8 @@ faxm = "!f(){ git fetch upstream master && git checkout -b ENG1FAXM-$1 upstream/master; }; f" drqs = "!f(){ git fetch upstream master && git checkout -b DRQS-$1 upstream/master; }; f" install-hooks = "!f(){ GIT_HOOKS=\"$(git rev-parse --git-dir)/hooks/\"; GOLDEN_HOOKS=\"$HOME/devel/scripts/git/hooks\"; [ -d \"$GIT_HOOKS\" ] && [ -d \"$GOLDEN_HOOKS\" ] && cp -r \"$GOLDEN_HOOKS/.\" \"$GIT_HOOKS\"; }; f" + refresh-master = "!f(){ git fetch upstream master; git checkout upstream/master; git branch -D master; git checkout -b master; }; f" + setup-upstream = "!source $HOME/devel/scripts/git/setup-upstream.sh" [merge] tool = vimdiff conflictstyle = diff3 diff --git a/git/setup-upstream.sh b/git/setup-upstream.sh new file mode 100755 index 0000000..c7cd8f0 --- /dev/null +++ b/git/setup-upstream.sh @@ -0,0 +1,51 @@ +#!/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 + +