Skip to content

Commit

Permalink
fix: gityaw when http remote was lacking ".git"
Browse files Browse the repository at this point in the history
Also made the regex code more readable for both functions.
  • Loading branch information
BarbzYHOOL committed Nov 11, 2018
1 parent 355fc95 commit 0443f12
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions functions/gitunyaw.fish
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ function gitunyaw -d "Replace Git SSH remote by HTTPS"
set ssh (command git remote get-url $remote)

if echo $ssh | grep -q 'https://.*'
echo "Git remote looks to be already a valid HTTPS remote"
echo "Git remote looks to be already a valid HTTPS remote"
else
set regex 's/git@\(.*\):\(.*\)\/\(.*\)\.git/https:\/\/\1\/\2\/\3.git/'
echo $ssh | sed -e "$regex" | read -l https
## Replace remote with sed (extended regexp) then assign to variable $https
echo $ssh | sed -E "s~git@(.*):(.*)/(.*)\.git~https://\1/\2/\3.git~" | read -l https
command git remote set-url "$remote" "$https"
echo "Replaced '$ssh' by '$https'"
end
Expand Down
6 changes: 3 additions & 3 deletions functions/gityaw.fish
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ function gityaw -d "Replace Git HTTPS remote by SSH"
set https (command git remote get-url $remote)

if echo $https | grep -q '.*@.*:.*'
echo "Git remote looks to be already a valid SSH remote"
echo "Git remote looks to be already a valid SSH remote"
else
set regex 's/https:\/\/\(.*\)\/\(.*\)\/\(.*\)\(.git\)*/git@\1:\2\/\3.git/'
echo $https | sed -e "$regex" | sed -e 's/\.git\.git$/\.git/' | read -l ssh
## Replace remote with sed (extended regexp) then assign to variable $ssh
echo $https | sed -E "s~https://(.*)/(.*)/(.*)(/|.git)~git@\1:\2\/\3.git~" | read -l ssh
command git remote set-url "$remote" "$ssh"
echo "Replaced '$https' by '$ssh'"
end
Expand Down

0 comments on commit 0443f12

Please sign in to comment.