Skip to content

Commit faa358d

Browse files
committed
Add support for git external subpath checkouts
`Libs/LibName: repo_url.git/some/subpath` in the short form or ` path: some/subpath` in the long form Closes #143
1 parent 649e0ae commit faa358d

File tree

1 file changed

+53
-16
lines changed

1 file changed

+53
-16
lines changed

release.sh

+53-16
Original file line numberDiff line numberDiff line change
@@ -861,14 +861,19 @@ wowi_convert_changelog="true"
861861
declare -A relations=()
862862

863863
parse_ignore() {
864-
pkgmeta="$1"
864+
pkgmeta="$1" # full path to .pkgmeta
865+
copy_path="$2" # the post-copy base path to match
866+
sub_path="$3" # only includes matches in this path
867+
865868
[ -f "$pkgmeta" ] || return 1
866869

867-
checkpath="$topdir" # paths are relative to the topdir
868-
copypath=""
869-
if [ "$2" != "" ]; then
870-
checkpath=$( dirname "$pkgmeta" )
871-
copypath="$2/"
870+
check_path="$topdir/" # paths are relative to the topdir
871+
if [ -n "$copy_path" ]; then
872+
check_path=$( dirname "$pkgmeta" )"/"
873+
copy_path="$copy_path/"
874+
fi
875+
if [[ -n $sub_path && $sub_path != *"/" ]]; then
876+
sub_path="$sub_path/"
872877
fi
873878

874879
yaml_eof=
@@ -892,15 +897,16 @@ parse_ignore() {
892897
yaml_line=${yaml_line#"${yaml_line%%[! ]*}"} # trim leading whitespace
893898
# Get the YAML list item.
894899
yaml_listitem "$yaml_line"
895-
if [[ "$pkgmeta_phase" == "ignore" || "$pkgmeta_phase" == "plain-copy" ]]; then
896-
pattern=$yaml_item
897-
if [ -d "$checkpath/$pattern" ]; then
898-
pattern="$copypath$pattern/*"
899-
elif [ ! -f "$checkpath/$pattern" ]; then
900+
if [[ "$pkgmeta_phase" == "ignore" || "$pkgmeta_phase" == "plain-copy" ]] && [[ $yaml_item == "$sub_path"* ]]; then
901+
yaml_item=${yaml_item%"/*"} # trim dir glob
902+
pattern=${yaml_item#$sub_path} # match relative to sub_path
903+
if [ -d "$check_path$yaml_item" ]; then
904+
pattern="$copy_path$pattern/*"
905+
elif [ ! -f "$copy_path$yaml_item" ]; then
900906
# doesn't exist so match both a file and a path
901-
pattern="$copypath$pattern:$copypath$pattern/*"
907+
pattern="$copy_path$pattern:$copy_path$pattern/*"
902908
else
903-
pattern="$copypath$pattern"
909+
pattern="$copy_path$pattern"
904910
fi
905911
if [[ "$pkgmeta_phase" == "ignore" ]]; then
906912
if [ -z "$ignore" ]; then
@@ -1866,6 +1872,7 @@ checkout_external() {
18661872
# shellcheck disable=SC2034
18671873
_external_slug=$5 # unused until we can easily fetch the project id
18681874
_external_checkout_type=$6
1875+
_external_path=$7
18691876

18701877
_cqe_checkout_dir="$pkgdir/$_external_dir/.checkout"
18711878
if [[ -d $_cqe_checkout_dir ]]; then
@@ -1971,8 +1978,14 @@ checkout_external() {
19711978
if [[ "$_external_uri" == *"wowace.com"* || "$_external_uri" == *"curseforge.com"* ]]; then
19721979
project_site="https://wow.curseforge.com"
19731980
fi
1981+
19741982
# If a .pkgmeta file is present, process it for "ignore" and "plain-copy" lists.
1975-
parse_ignore "$_cqe_checkout_dir/.pkgmeta" "$_external_dir"
1983+
parse_ignore "$_cqe_checkout_dir/.pkgmeta" "$_external_dir" "$_external_path"
1984+
if [ -n "$_external_path" ]; then
1985+
echo "Changing to /$_external_path"
1986+
_cqe_checkout_dir="$_cqe_checkout_dir/$_external_path"
1987+
cd "$_cqe_checkout_dir" || return 1
1988+
fi
19761989
copy_directory_tree -dnpe -i "$ignore" -u "$unchanged" "$_cqe_checkout_dir" "$pkgdir/$_external_dir"
19771990
) || return 1
19781991
# Remove the ".checkout" subdirectory containing the full checkout.
@@ -1989,8 +2002,13 @@ external_tag=
19892002
external_type=
19902003
external_slug=
19912004
external_checkout_type=
2005+
external_path=
19922006
process_external() {
19932007
if [ -n "$external_dir" ] && [ -n "$external_uri" ] && [ -z "$skip_externals" ]; then
2008+
external_uri=${external_uri%%#*} # strip trailing comment
2009+
external_uri=${external_uri% *} # strip trailing space
2010+
external_uri=${external_uri%/} # strip trailing slash
2011+
19942012
# convert old curse repo urls
19952013
case $external_uri in
19962014
*git.curseforge.com*|*git.wowace.com*)
@@ -2029,7 +2047,7 @@ process_external() {
20292047
fi
20302048

20312049
# check if the repo is svn
2032-
_svn_path=${external_uri#*/wow/$external_slug/}
2050+
local _svn_path=${external_uri#*/wow/$external_slug/}
20332051
if [[ "$_svn_path" == "trunk"* ]]; then
20342052
external_type="svn"
20352053
elif [[ "$_svn_path" == "tags/"* ]]; then
@@ -2041,12 +2059,29 @@ process_external() {
20412059
fi
20422060
fi
20432061

2062+
if [[ $external_type == "git" ]]; then
2063+
# check for subpath in short form
2064+
if [[ -n $external_slug && $external_uri == *"$external_slug/"* ]]; then
2065+
# CF: `Libs/LibDoThings-1.0: https://repos.curseforge.com/wow/libdothings-1-0/LibDoThings-1.0`
2066+
external_path=${external_uri#*/wow/$external_slug/}
2067+
external_uri=${external_uri%/$external_path*}
2068+
elif [[ $external_uri == *".git/"* ]]; then
2069+
# Anything using .git: `Libs/LibDoThings-1.0: https://github.com/nebularg/LibDoThings-1.0.git/LibDoThings-1.0`
2070+
external_path=${external_uri#*.git/}
2071+
external_uri=${external_uri%/$external_path*}
2072+
elif [[ $external_uri == "https://github.com/"*/*/* ]]; then
2073+
# Github without .git: `Libs/LibDoThings-1.0: https://github.com/nebularg/LibDoThings-1.0/LibDoThings-1.0`
2074+
external_path=${external_uri#*.com/*/*/}
2075+
external_uri=${external_uri%/$external_path*}
2076+
fi
2077+
fi
2078+
20442079
if [ -n "$external_slug" ]; then
20452080
relations["${external_slug,,}"]="embeddedLibrary"
20462081
fi
20472082

20482083
echo "Fetching external: $external_dir"
2049-
checkout_external "$external_dir" "$external_uri" "$external_tag" "$external_type" "$external_slug" "$external_checkout_type" &> "$releasedir/.$BASHPID.externalout" &
2084+
checkout_external "$external_dir" "$external_uri" "$external_tag" "$external_type" "$external_slug" "$external_checkout_type" "$external_path" &> "$releasedir/.$BASHPID.externalout" &
20502085
external_pids+=($!)
20512086
fi
20522087
external_dir=
@@ -2055,6 +2090,7 @@ process_external() {
20552090
external_type=
20562091
external_slug=
20572092
external_checkout_type=
2093+
external_path=
20582094
}
20592095

20602096
# Don't leave extra files around if exited early
@@ -2110,6 +2146,7 @@ if [ -z "$skip_externals" ] && [ -f "$pkgmeta_file" ]; then
21102146
;;
21112147
type) external_type=$yaml_value ;;
21122148
curse-slug) external_slug=$yaml_value ;;
2149+
path) external_path=$yaml_value ;;
21132150
*)
21142151
# Started a new external, so checkout any queued externals.
21152152
process_external

0 commit comments

Comments
 (0)