forked from mhartl/git-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-pull-request
More file actions
executable file
·47 lines (42 loc) · 1.35 KB
/
Copy pathgit-pull-request
File metadata and controls
executable file
·47 lines (42 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
# Copyright (c) 2013 Michael Hartl
# Released under the MIT License (http://opensource.org/licenses/MIT)
# Issues a pull request.
URL=`git config --get remote.origin.url`
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
SERVICE=stash
PROTOCOL=ssh
if [[ $URL =~ bitbucket ]]
then
SERVICE=bitbucket
elif [[ $URL =~ github ]]
then
SERVICE=github
fi
if [[ $URL =~ https:// || $URL =~ http:// ]]
then
PROTOCOL=http
fi
case $SERVICE-$PROTOCOL in
stash-ssh )
# If it's ssh, drop the port
GIT_PATTERN='s/(.*)@([^:]*):?([^\/]*)\/([^\/]*)\/(.*)\.git/https:\/\/\2\/projects\/\4\/repos\/\5\/pull-requests\?create\&sourceBranch='"$CURRENT_BRANCH"/
;;
stash-http )
GIT_PATTERN='s/(.*)@([^:\/]*)(:?[^\/]*)\/(.*)scm\/([^\/]*)\/(.*)\.git/https:\/\/\2\3\/\4projects\/\5\/repos\/\6\/pull-requests\?create\&sourceBranch='"$CURRENT_BRANCH"/
;;
github-ssh )
GIT_PATTERN='s/(.*)@(.*):(.*)\.git/https:\/\/\2\/\3\/pull\/new\/'"$CURRENT_BRANCH"/
;;
github-http )
GIT_PATTERN='s/https?\:\/\/(([^@]*)@)?(.*)\.git/https:\/\/\3\/pull\/new\/'"$CURRENT_BRANCH"/
;;
bitbucket-ssh )
GIT_PATTERN='s/(.*)@(.*):(.*)\.git/https:\/\/\2\/\3\/pull-request\/new/'
;;
bitbucket-http )
GIT_PATTERN='s/https?\:\/\/(([^@]*)@)?(.*)\.git/https:\/\/\3\/pull-request\/new/'
;;
esac
git push-branch
echo $URL | sed -E $GIT_PATTERN | xargs open