mirror of
https://github.com/jorgebucaran/fisher
synced 2024-10-09 09:36:53 +02:00
Add default (main) tag fallback support; fix #583
When adding packages without specifying the tag/branch, e.g. fisher add jorgebucaran/nvm.fish we'll try to download it from the `/main` tag by default and if that fails, fallback to `/master`.
This commit is contained in:
parent
c20d1b3ec3
commit
d7035f3f4e
1 changed files with 16 additions and 17 deletions
33
fisher.fish
33
fisher.fish
|
@ -292,29 +292,28 @@ function _fisher_fetch
|
||||||
|
|
||||||
command awk -v PKG="$pkg" -v FS=/ '
|
command awk -v PKG="$pkg" -v FS=/ '
|
||||||
BEGIN {
|
BEGIN {
|
||||||
if (split(PKG, tmp, /@+|:/) > 2) {
|
split(PKG, tmp, /@/)
|
||||||
if (tmp[4]) sub("@"tmp[4], "", PKG)
|
pkg = split(PKG, _, "/") <= 2 ? "github.com/"tmp[1] : tmp[1]
|
||||||
print PKG "\t" tmp[2]"/"tmp[1]"/"tmp[3] "\t" (tmp[4] ? tmp[4] : "master")
|
print pkg "\t" url(pkg, (tmp[2] ? tmp[2] : "main")) "\t" (tmp[2] ? "" : url(pkg, "master"))
|
||||||
} else {
|
|
||||||
pkg = split(PKG, _, "/") <= 2 ? "github.com/"tmp[1] : tmp[1]
|
|
||||||
tag = tmp[2] ? tmp[2] : "master"
|
|
||||||
print (\
|
|
||||||
pkg ~ /^github/ ? "https://codeload."pkg"/tar.gz/"tag : \
|
|
||||||
pkg ~ /^gitlab/ ? "https://"pkg"/-/archive/"tag"/"tmp[split(pkg, tmp, "/")]"-"tag".tar.gz" : \
|
|
||||||
pkg ~ /^bitbucket/ ? "https://"pkg"/get/"tag".tar.gz" : pkg \
|
|
||||||
) "\t" pkg
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
' | read -l url pkg branch
|
function url(pkg, tag) {
|
||||||
|
return \
|
||||||
|
pkg ~ /^github/ ? "https://codeload."pkg"/tar.gz/"tag : \
|
||||||
|
pkg ~ /^gitlab/ ? "https://"pkg"/-/archive/"tag"/"tmp[split(pkg, tmp, "/")]"-"tag".tar.gz" : \
|
||||||
|
pkg ~ /^bitbucket/ ? "https://"pkg"/get/"tag".tar.gz" : pkg
|
||||||
|
}
|
||||||
|
' | read -l pkg url url_fallback
|
||||||
|
|
||||||
if test ! -d "$fisher_data/$pkg"
|
if test ! -d "$fisher_data/$pkg"
|
||||||
fish -c "
|
fish -c "
|
||||||
echo fetching $url >&2
|
echo fetching $url >&2
|
||||||
command mkdir -p $fisher_data/$pkg $fisher_cache/(command dirname $pkg)
|
command mkdir -p $fisher_data/$pkg $fisher_cache/(command dirname $pkg)
|
||||||
if test ! -z \"$branch\"
|
if command curl $curl_opts -Ss -w \"\" $url 2>&1 | command tar -xzf- -C $fisher_data/$pkg 2>/dev/null
|
||||||
command git clone $url $fisher_data/$pkg --branch $branch --depth 1 2>/dev/null
|
or begin
|
||||||
or echo fisher: cannot clone \"$url\" -- is this a valid url\? >&2
|
test ! -z \"$url_fallback\"
|
||||||
else if command curl $curl_opts -Ss -w \"\" $url 2>&1 | command tar -xzf- -C $fisher_data/$pkg 2>/dev/null
|
and echo fallback $url_fallback >&2
|
||||||
|
and command curl $curl_opts -Ss -w \"\" $url_fallback 2>&1 | command tar -xzf- -C $fisher_data/$pkg 2>/dev/null
|
||||||
|
end
|
||||||
command rm -Rf $fisher_cache/$pkg
|
command rm -Rf $fisher_cache/$pkg
|
||||||
command mv -f $fisher_data/$pkg/* $fisher_cache/$pkg
|
command mv -f $fisher_data/$pkg/* $fisher_cache/$pkg
|
||||||
command rm -Rf $fisher_data/$pkg
|
command rm -Rf $fisher_data/$pkg
|
||||||
|
|
Loading…
Reference in a new issue