Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions bin/git-browse
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ fi
# construct urls
commit_hash=$(git rev-parse HEAD 2>/dev/null)
commit_or_branch=${commit_hash:-${branch}}
full_filename=$(git ls-files --full-name "${filename}")

if [[ $remote_url =~ gitlab ]]; then
# construct gitlab urls
# https://gitlab.com/<user_or_group>/<repo>/-/blob/<commit_or_branch>/<filename>#L<line1>-<line2>
if [[ -n ${filename} ]]; then
url="${url}/-/blob/${commit_or_branch}/${filename}"
url="${url}/-/blob/${commit_or_branch}/${full_filename}"
if [[ -n "${line1}" ]]; then
url="${url}#L${line1}"
if [[ -n "${line2}" ]]; then
Expand All @@ -45,7 +46,7 @@ elif [[ $remote_url =~ github ]]; then
# construct github urls
# https://github.com/<user_or_org>/<repo>/blob/<commit_or_branch>/<filename>#L<line1>-L<line2>
if [[ -n "${filename}" ]]; then
url="${url}/blob/${commit_or_branch}/${filename}"
url="${url}/blob/${commit_or_branch}/${full_filename}"
if [[ -n "${line1}" ]]; then
url="${url}#L${line1}"
if [[ -n "${line2}" ]]; then
Expand All @@ -57,7 +58,7 @@ elif [[ $remote_url =~ bitbucket ]]; then
# construct bitbucket urls
# https://bitbucket.org/<user_or_org>/<repo>/src/<commit_or_branch>/<filename>#lines-<line1>:<line2>
if [[ -n ${filename} ]]; then
url=${url}/src/${commit_or_branch}/${filename}
url=${url}/src/${commit_or_branch}/${full_filename}
if [[ -n "${line1}" ]]; then
url="${url}#lines-${line1}"
if [[ -n "${line2}" ]]; then
Expand Down
6 changes: 3 additions & 3 deletions tests/git-browse.bats
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ get_file_uri() {
local commit_hash=
commit_hash=$(git rev-parse HEAD)
if [ "$mode" = 'github' ]; then
REPLY="https://github.com/tj/git-extras/blob/$commit_hash/${filename}"
REPLY="https://github.com/tj/git-extras/blob/$commit_hash/${filename#./}"
elif [ "$mode" = 'gitlab' ]; then
REPLY="https://gitlab.com/tj/git-extras/-/blob/${commit_hash}/${filename}"
REPLY="https://gitlab.com/tj/git-extras/-/blob/${commit_hash}/${filename#./}"
elif [ "$mode" = 'bitbucket' ]; then
REPLY="https://bitbucket.org/tj/git-extras/src/${commit_hash}/${filename}"
REPLY="https://bitbucket.org/tj/git-extras/src/${commit_hash}/${filename#./}"
fi
}

Expand Down
Loading