Skip to content

Commit 6e9da2a

Browse files
authored
Merge pull request #641 from tj/fix_pull_request_upstream
pull_request: should use detected upstream instead of hardcore origin
2 parents b00aace + 344b145 commit 6e9da2a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

bin/git-pull-request

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,22 @@ test -z "$user" && abort "git config user.email required"
4141
# branch
4242

4343
branch=${1-$(git symbolic-ref HEAD | sed 's/refs\/heads\///')}
44+
remote=$(git config branch."$branch".remote)
45+
if [ -z "$remote" ]; then
46+
echo 'no upstream found, push to origin as default'
47+
remote="origin"
48+
fi
49+
[ "$remote" == "." ] && abort "the upstream should be a remote branch."
4450

4551
# make sure it's pushed
4652

47-
git push origin "$branch" || abort "failed to push $branch"
53+
git push "$remote" "$branch" || abort "failed to push $branch"
4854

49-
origin=$(git config remote.origin.url)
50-
if [[ $origin == git@* ]]; then
51-
project=${origin##*:}
55+
remote_url=$(git config remote."$remote".url)
56+
if [[ "$remote_url" == git@* ]]; then
57+
project=${remote_url##*:}
5258
else
53-
project=${origin#https://*/}
59+
project=${remote_url#https://*/}
5460
fi
5561
project=${project%.git}
5662

0 commit comments

Comments
 (0)