-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGit_http_to_ssh.sh
More file actions
21 lines (21 loc) · 868 Bytes
/
Git_http_to_ssh.sh
File metadata and controls
21 lines (21 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
function git_http_to_ssh {
local name=${1}
local name=${name:=origin}
local url=$( git remote get-url $name )
[[ "$url" =~ (http[s]?)://(.+)/(.+)/(.+)(\.git)? ]]
local protocol="${BASH_REMATCH[1]}"
if [ \( "$protocol" == "http" \) -o \( "$protocol" == "https" \) ] ;then
local provider="${BASH_REMATCH[2]}"
local team="${BASH_REMATCH[3]}"
local prj="${BASH_REMATCH[4]}"
local ext="${BASH_REMATCH[5]}"
company=$(fgrep Host ~/.ssh/config | fgrep -v Hostname | cut -d' ' -f2)
if [ X"${company}" != "X" -a X"${provider}" == "Xbitbucket.org" -a -f "~/.ssh/id_rsa_${team}" ] ;then
provider="${company}"
fi
git remote set-url $name "git@${provider}:${team}/${prj}${ext}"
git remote set-url --push $name "git@${provider}:${team}/${prj}${ext}"
fi
}
git_http_to_ssh $@