|
|
@ -5,31 +5,43 @@
|
|
|
|
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
|
|
|
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
local remote branches branch current_branch file url
|
|
|
|
local remotes remote references reference file url
|
|
|
|
|
|
|
|
|
|
|
|
remote="${1:-origin}"
|
|
|
|
remote="${1:-origin}"
|
|
|
|
|
|
|
|
remotes=($(
|
|
|
|
|
|
|
|
git config --local --get-regexp 'remote.*.url' \
|
|
|
|
|
|
|
|
| awk 'BEGIN {FS="."} ; {print $2}'
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (( $remotes[(i)$remote] == $#remotes + 1 )); then
|
|
|
|
|
|
|
|
print "$0: remote not found: $remote" >&2
|
|
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
url=$(
|
|
|
|
url=$(
|
|
|
|
git config --local --get "remote.${remote}.url" \
|
|
|
|
git config --local --get "remote.${remote}.url" \
|
|
|
|
| sed -En "s/(git|https?)(@|:\/\/)github.com(:|\/)(.+)\/(.+).git/https:\/\/github.com\/\4\/\5/p"
|
|
|
|
| sed -En "s/(git|https?)(@|:\/\/)github.com(:|\/)(.+)\/(.+).git/https:\/\/github.com\/\4\/\5/p"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
branches=($(
|
|
|
|
|
|
|
|
git ls-remote --heads "$remote" \
|
|
|
|
|
|
|
|
| awk '{gsub(/refs\/heads\//, "", $2)} ; {print $2}'
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
current_branch="$(git-branch-current)"
|
|
|
|
|
|
|
|
branch="${2:-master}"
|
|
|
|
|
|
|
|
file="$3"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [[ -z "$2" ]]; then
|
|
|
|
reference="${${2:-$(git-branch-current)}:-HEAD}"
|
|
|
|
if (( $branches[(I)$current_branch] != 0 )); then
|
|
|
|
references=(
|
|
|
|
branch="$current_branch"
|
|
|
|
HEAD
|
|
|
|
else
|
|
|
|
${$(git ls-remote --heads --tags "$remote" | awk '{print $2}')##refs/(heads|tags)/}
|
|
|
|
branch='master'
|
|
|
|
)
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if (( $references[(i)$reference] == $#references + 1 )); then
|
|
|
|
|
|
|
|
print "$0: branch or tag not found: $reference" >&2
|
|
|
|
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [[ "$reference" == 'HEAD' ]]; then
|
|
|
|
|
|
|
|
reference="$(git rev-parse HEAD 2>/dev/null)"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file="$3"
|
|
|
|
|
|
|
|
|
|
|
|
if [[ -n "$url" ]]; then
|
|
|
|
if [[ -n "$url" ]]; then
|
|
|
|
url="${url}/tree/${branch}/${file}"
|
|
|
|
url="${url}/tree/${reference}/${file}"
|
|
|
|
|
|
|
|
|
|
|
|
if (( $+commands[$BROWSER] )); then
|
|
|
|
if (( $+commands[$BROWSER] )); then
|
|
|
|
"$BROWSER" "$url"
|
|
|
|
"$BROWSER" "$url"
|
|
|
@ -39,7 +51,7 @@ if [[ -n "$url" ]]; then
|
|
|
|
return 1
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
else
|
|
|
|
print "$0: not a Git repository or remote origin not set" >&2
|
|
|
|
print "$0: not a Git repository or remote not set" >&2
|
|
|
|
return 1
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|