Skip to content

Commit df7712c

Browse files
committed
Add support for bitbucket repos cloned with ssh
Signed-off-by: Prabhu Jayakumar <j.prabhu91@gmail.com>
1 parent 14fdf5c commit df7712c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

git-open

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ elif [[ "${#pathargs[@]}" -ge 3 && ${pathargs[${#pathargs[@]} - 3]} == 'scm' ]];
199199
pathargs=(${pathPref[@]} 'projects' ${pathargs[${#pathargs[@]} - 2]} 'repos' "${pathargs[@]:${#pathargs[@]} - 1}")
200200
IFS='/' urlpath="${pathargs[*]}"
201201
providerBranchRef="/browse?at=$remote_ref"
202+
elif [[ "$domain" == *"bitbucket"* ]] && [[ $gitprotocol == 'ssh' ]]; then
203+
# bitbucket repo cloned with ssh will not have /scm/ segment in url path
204+
# e.g. /ppp/test-repo.git
205+
206+
# Build the repo url starting with 'projects' and then keep the first argument, the string 'repos', and finally the rest of the arguments.
207+
# shellcheck disable=SC2206
208+
pathargs=('projects' ${pathargs[${#pathargs[@]} - 2]} 'repos' "${pathargs[@]:${#pathargs[@]} - 1}")
209+
IFS='/' urlpath="${pathargs[*]}"
210+
providerBranchRef="/browse?at=$remote_ref"
202211
elif [[ "${#pathargs[@]}" -ge '2' && ${pathargs[${#pathargs[@]} - 2]} == '_git' ]]; then
203212
# Visual Studio Team Services and Team Foundation Server always have /_git/ as the second to last segment in the url path
204213
if (( is_issue )); then

test/git-open.bats

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,13 @@ setup() {
472472
assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=refs/heads/develop"
473473
}
474474

475+
@test "bitbucket: Selfhosted Bitbucket Server with ssh:// clone urls" {
476+
# https://github.com/paulirish/git-open/pull/174
477+
git remote set-url origin "ssh://git@bitbucket.domain.com/ppp/rrr.git"
478+
run ../git-open
479+
assert_output "https://bitbucket.domain.com/projects/ppp/repos/rrr"
480+
}
481+
475482

476483
##
477484
## GitLab

0 commit comments

Comments
 (0)