File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ function git_http_to_ssh {
4
+ local name=${1}
5
+ local name=${name:= origin}
6
+ local url=$( git remote get-url $name )
7
+ [[ " $url " =~ (http[s]? )://(.+)/(.+)/(.+)(\. git)? ]]
8
+ local protocol=" ${BASH_REMATCH[1]} "
9
+ if [ \( " $protocol " == " http" \) -o \( " $protocol " == " https" \) ] ; then
10
+ local provider=" ${BASH_REMATCH[2]} "
11
+ local team=" ${BASH_REMATCH[3]} "
12
+ local prj=" ${BASH_REMATCH[4]} "
13
+ local ext=" ${BASH_REMATCH[5]} "
14
+ company=$( fgrep Host ~ /.ssh/config | fgrep -v Hostname | cut -d' ' -f2)
15
+ if [ X" ${company} " != " X" -a X" ${provider} " == " Xbitbucket.org" -a -f " ~/.ssh/id_rsa_${team} " ] ; then
16
+ provider=" ${company} "
17
+ fi
18
+ git remote set-url $name " git@${provider} :${team} /${prj}${ext} "
19
+ git remote set-url --push $name " git@${provider} :${team} /${prj}${ext} "
20
+ fi
21
+ }
22
+ git_http_to_ssh $@
You can’t perform that action at this time.
0 commit comments