Skip to content

Commit

Permalink
fix: Use absolute (relative to repo root) path to supplied filename
Browse files Browse the repository at this point in the history
If a file is referenced from the subdir of a repository, the script
confirms it exists and tacks the filename onto the URL, but doesn't
check if the filename provided is relative to the repo root.
  • Loading branch information
mattcen committed Aug 8, 2024
1 parent c32869d commit 4bbf264
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions bin/git-browse
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ 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}/$(git ls-files --full-name "${filename}")"
if [[ -n "${line1}" ]]; then
url="${url}#L${line1}"
if [[ -n "${line2}" ]]; then
Expand All @@ -45,7 +45,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}/$(git ls-files --full-name "${filename}")"
if [[ -n "${line1}" ]]; then
url="${url}#L${line1}"
if [[ -n "${line2}" ]]; then
Expand All @@ -57,7 +57,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}/$(git ls-files --full-name "${filename}")
if [[ -n "${line1}" ]]; then
url="${url}#lines-${line1}"
if [[ -n "${line2}" ]]; then
Expand Down

0 comments on commit 4bbf264

Please sign in to comment.