diff --git a/bin/git-browse b/bin/git-browse index aee6d7eb0..06e0c0f06 100755 --- a/bin/git-browse +++ b/bin/git-browse @@ -8,7 +8,7 @@ line2=${4:-""} # get remote name if [[ $remote == "" ]]; then - branch=$(git rev-parse --abbrev-ref HEAD 2 &>/dev/null) + branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)" remote=$(git config branch."${branch}".remote || echo "origin") fi @@ -31,14 +31,14 @@ elif [[ $remote_url = http* ]]; then fi # construct urls -commit_hash=$(git log -n1 --format=format:"%H" "${filename}" 2>/dev/null) +commit_hash=$(git rev-parse HEAD 2>/dev/null) commit_or_branch=${commit_hash:-${branch}} if [[ $remote_url =~ gitlab ]]; then # construct gitlab urls # https://gitlab.com///-/blob//#L- if [[ -n ${filename} ]]; then - url="${url}/-/blob/${commit_hash:-${branch}}/${filename}" + url="${url}/-/blob/${commit_or_branch}/${filename}" if [[ -n "${line1}" ]]; then url="${url}#L${line1}" if [[ -n "${line2}" ]]; then @@ -50,7 +50,7 @@ elif [[ $remote_url =~ github ]]; then # construct github urls # https://github.com///blob//#L-L if [[ -n "${filename}" ]]; then - url="${url}/blob/${commit_hash:-${branch}}/${filename}" + url="${url}/blob/${commit_or_branch}/${filename}" if [[ -n "${line1}" ]]; then url="${url}#L${line1}" if [[ -n "${line2}" ]]; then @@ -62,7 +62,7 @@ elif [[ $remote_url =~ bitbucket ]]; then # construct bitbucket urls # https://bitbucket.org///src//#lines-: if [[ -n ${filename} ]]; then - url=${url}/src/${commit_hash:-${branch}}/${filename} + url=${url}/src/${commit_or_branch}/${filename} if [[ -n "${line1}" ]]; then url="${url}#lines-${line1}" if [[ -n "${line2}" ]]; then