diff --git a/git-open b/git-open index 38abbb7..bc51784 100755 --- a/git-open +++ b/git-open @@ -50,14 +50,16 @@ IFS='/' pathargs=($urlpath) providerBranchRef="tree/$branch" if [[ "$server" == 'bitbucket.org' ]]; then - # Bitbucket, see https://github.com/paulirish/git-open/issues/80 for why ?at is needed. - providerBranchRef="src?at=$branch" + # Bitbucket, see https://github.com/paulirish/git-open/issues/80 for why the ref and the ?at is needed. + ref=$(git rev-parse --short $branch) + providerBranchRef="src/$ref?at=$branch" elif [[ ${pathargs[0]} == 'scm' ]]; then # Bitbucket server, which starts with 'scm' # Replace the first element, 'scm', with 'projects'. Keep the first argument, the string 'repos', and finally the rest of the arguments. pathargs=('projects' ${pathargs[1]} 'repos' "${pathargs[@]:2}") IFS='/' urlpath="${pathargs[*]}" - providerBranchRef="browse?at=$branch" + ref=$(git rev-parse --short $branch) + providerBranchRef="browse/$ref?at=$branch" fi # @TODO: support non-https? diff --git a/test/git-open.bats b/test/git-open.bats index 2b48982..20d54d8 100644 --- a/test/git-open.bats +++ b/test/git-open.bats @@ -123,11 +123,9 @@ setup() { git remote set-url origin "https://bitbucket.org/kisom/consbri.git" git checkout -B "devel" run ../git-open - assert_output "https://bitbucket.org/kisom/consbri/src/devel" + ref=$(git rev-parse --short devel) + assert_output "https://bitbucket.org/kisom/consbri/src/$ref?at=devel" refute_output --partial "//" - - # alternative destination.. - # assert_output "https://bitbucket.org/kisom/consbri/src/?at=devel" } @test "bitbucket: open source view with a slash/branch" { @@ -167,7 +165,8 @@ setup() { git remote set-url origin "https://user@bitbucket.example.com/scm/ppp/test-repo.git" git checkout -B "bb-server" run ../git-open - assert_output "https://bitbucket.example.com/projects/ppp/repos/test-repo/browse?at=bb-server" + ref=$(git rev-parse -q --short HEAD) + assert_output "https://bitbucket.example.com/projects/ppp/repos/test-repo/browse/$ref?at=bb-server" }