From 344b145062538be2ee109d4145cdc2bea48409f8 Mon Sep 17 00:00:00 2001 From: spacewander Date: Sun, 19 Mar 2017 01:07:00 +0800 Subject: [PATCH 1/2] git-pull-request: use detected upstream remote --- bin/git-pull-request | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bin/git-pull-request b/bin/git-pull-request index 9872880..a011314 100755 --- a/bin/git-pull-request +++ b/bin/git-pull-request @@ -41,16 +41,22 @@ test -z "$user" && abort "git config user.email required" # branch branch=${1-$(git symbolic-ref HEAD | sed 's/refs\/heads\///')} +remote=$(git config branch."$branch".remote) +if [ -z "$remote" ]; then + echo 'no upstream found, push to origin as default' + remote="origin" +fi +[ "$remote" == "." ] && abort "the upstream should be a remote branch." # make sure it's pushed -git push origin "$branch" || abort "failed to push $branch" +git push "$remote" "$branch" || abort "failed to push $branch" -origin=$(git config remote.origin.url) -if [[ $origin == git@* ]]; then - project=${origin##*:} +remote_url=$(git config remote."$remote".url) +if [[ "$remote_url" == git@* ]]; then + project=${remote_url##*:} else - project=${origin#https://*/} + project=${remote_url#https://*/} fi project=${project%.git} From 4a05ad29e4bf31d33ada793750fb4712a3167aa7 Mon Sep 17 00:00:00 2001 From: spacewander Date: Sun, 19 Mar 2017 01:56:33 +0800 Subject: [PATCH 2/2] git-rename-branch: use detected upstream remote --- bin/git-rename-branch | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/git-rename-branch b/bin/git-rename-branch index 0ea2a66..b0a0769 100755 --- a/bin/git-rename-branch +++ b/bin/git-rename-branch @@ -1,11 +1,17 @@ #!/usr/bin/env bash +set -e # Assert there is at least one branch provided test -z $1 && echo "new branch name required." 1>&2 && exit 1 new_branch="$1" old_branch="${2-$(git symbolic-ref --short -q HEAD)}" +remote=$(git config branch."$old_branch".remote) git branch -m "$old_branch" "$new_branch" -git push origin :"$old_branch" -git push --set-upstream origin "$new_branch" +# check if the branch is tracking a remote branch +if [[ -n "$remote" && "$remote" != "." ]] +then + git push "$remote" :"$old_branch" + git push --set-upstream "$remote" "$new_branch" +fi