Skip to content

Commit beebcdb

Browse files
authored
Merge pull request #113 from nwinkler/bb-server-context
Bitbucket Server Root Context
2 parents 51caa23 + 140edbb commit beebcdb

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

git-open

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,15 @@ fi
126126
if [[ "$domain" == 'bitbucket.org' ]]; then
127127
# Bitbucket, see https://github.com/paulirish/git-open/issues/80 for why ?at is needed.
128128
providerBranchRef="/src?at=$branch"
129-
elif [[ ${pathargs[0]} == 'scm' ]]; then
130-
# Bitbucket server, which starts with 'scm'
131-
# Replace the first element, 'scm', with 'projects'. Keep the first argument, the string 'repos', and finally the rest of the arguments.
132-
pathargs=('projects' ${pathargs[1]} 'repos' "${pathargs[@]:2}")
129+
elif [[ "${#pathargs[@]}" -ge 3 && ${pathargs[${#pathargs[@]} - 3]} == 'scm' ]]; then
130+
# Bitbucket server always has /scm/ as the third to last segment in the url path, e.g. /scm/ppp/test-repo.git
131+
# Anything before the 'scm' is part of the server's root context
132+
133+
# If there are other context parts, add them, up to (but not including) the found 'scm'
134+
pathPref=("${pathargs[*]:0:${#pathargs[@]} - 3}")
135+
136+
# Replace the 'scm' element, with 'projects'. Keep the first argument, the string 'repos', and finally the rest of the arguments.
137+
pathargs=(${pathPref[@]} 'projects' ${pathargs[${#pathargs[@]} - 2]} 'repos' "${pathargs[@]:${#pathargs[@]} - 1}")
133138
IFS='/' urlpath="${pathargs[*]}"
134139
providerBranchRef="/browse?at=$branch"
135140
elif [[ "${#pathargs[@]}" -ge '2' && ${pathargs[${#pathargs[@]} - 2]} == '_git' ]]; then

test/git-open.bats

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -214,22 +214,6 @@ setup() {
214214
refute_output --partial "@"
215215
}
216216

217-
@test "bitbucket server" {
218-
# https://github.com/paulirish/git-open/pull/15
219-
git remote set-url origin "https://[email protected]/scm/ppp/test-repo.git"
220-
run ../git-open
221-
assert_output "https://bitbucket.example.com/projects/ppp/repos/test-repo"
222-
}
223-
224-
@test "bitbucket server branch" {
225-
# https://github.com/paulirish/git-open/pull/15
226-
git remote set-url origin "https://[email protected]/scm/ppp/test-repo.git"
227-
git checkout -B "bb-server"
228-
run ../git-open
229-
assert_output "https://bitbucket.example.com/projects/ppp/repos/test-repo/browse?at=bb-server"
230-
}
231-
232-
233217
@test "bitbucket: Bitbucket Server" {
234218
# https://github.com/paulirish/git-open/issues/77#issuecomment-309044010
235219
git remote set-url origin "https://[email protected]/scm/ppp/rrr.git"
@@ -269,6 +253,38 @@ setup() {
269253

270254
}
271255

256+
257+
@test "bitbucket: Bitbucket Server with different root context" {
258+
# https://github.com/paulirish/git-open/pull/15
259+
git remote set-url origin "https://[email protected]/git/scm/ppp/test-repo.git"
260+
run ../git-open
261+
assert_output "https://bitbucket.example.com/git/projects/ppp/repos/test-repo" ||
262+
assert_output "https://bitbucket.example.com/git/projects/ppp/repos/test-repo/?at=master" ||
263+
assert_output "https://bitbucket.example.com/git/projects/ppp/repos/test-repo/?at=refs%2Fheads%2Fmaster"
264+
}
265+
266+
267+
@test "bitbucket: Bitbucket Server with different root context with multiple parts" {
268+
# https://github.com/paulirish/git-open/pull/15
269+
git remote set-url origin "https://[email protected]/really/long/root/context/scm/ppp/test-repo.git"
270+
run ../git-open
271+
assert_output "https://bitbucket.example.com/really/long/root/context/projects/ppp/repos/test-repo" ||
272+
assert_output "https://bitbucket.example.com/really/long/root/context/projects/ppp/repos/test-repo/?at=master" ||
273+
assert_output "https://bitbucket.example.com/really/long/root/context/projects/ppp/repos/test-repo/?at=refs%2Fheads%2Fmaster"
274+
}
275+
276+
277+
@test "bitbucket: Bitbucket Server private user repos with different root context" {
278+
# https://github.com/paulirish/git-open/pull/83#issuecomment-309968538
279+
git remote set-url origin "https://mybb.domain.com/root/context/scm/~first.last/rrr.git"
280+
git checkout -B "develop"
281+
run ../git-open
282+
assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=develop" ||
283+
assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=refs%2Fheads%2Fdevelop" ||
284+
assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=refs/heads/develop"
285+
}
286+
287+
272288
##
273289
## GitLab
274290
##

0 commit comments

Comments
 (0)