mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
Refactor to remove duplication
This commit is contained in:
parent
16fb892d8f
commit
f26412eeae
|
|
@ -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}/$(git ls-files --full-name "${filename}")"
|
||||
url="${url}/-/blob/${commit_or_branch}/${full_filename}"
|
||||
if [[ -n "${line1}" ]]; then
|
||||
url="${url}#L${line1}"
|
||||
if [[ -n "${line2}" ]]; then
|
||||
|
|
@ -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}/$(git ls-files --full-name "${filename}")"
|
||||
url="${url}/blob/${commit_or_branch}/${full_filename}"
|
||||
if [[ -n "${line1}" ]]; then
|
||||
url="${url}#L${line1}"
|
||||
if [[ -n "${line2}" ]]; then
|
||||
|
|
@ -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}/$(git ls-files --full-name "${filename}")
|
||||
url=${url}/src/${commit_or_branch}/${full_filename}
|
||||
if [[ -n "${line1}" ]]; then
|
||||
url="${url}#lines-${line1}"
|
||||
if [[ -n "${line2}" ]]; then
|
||||
|
|
|
|||
Loading…
Reference in a new issue