aboutsummaryrefslogtreecommitdiffstats
path: root/examples/tools/clone.sh
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-19 20:42:12 +0200
committerDanilo M. <danix@danix.xyz>2026-10-19 20:42:12 +0200
commitf6a2524658e113561a102f86997f9e236f22e9d8 (patch)
tree4215899feca591308070480c46daa319a1c42726 /examples/tools/clone.sh
parent2d58a44858417510f31ab31bc6f6c54abdbc5503 (diff)
downloaddesktop-assistant-f6a2524658e113561a102f86997f9e236f22e9d8.tar.gz
desktop-assistant-f6a2524658e113561a102f86997f9e236f22e9d8.zip
clone tool: name the target owner-repo
A generic repo such as evgen2571/wallpapers cloned into wallpapers; the target now takes the owner's name, collapsing when owner and repo match and falling back to the bare name when the URL has none.
Diffstat (limited to 'examples/tools/clone.sh')
-rwxr-xr-xexamples/tools/clone.sh24
1 files changed, 19 insertions, 5 deletions
diff --git a/examples/tools/clone.sh b/examples/tools/clone.sh
index e4051fc..f08b932 100755
--- a/examples/tools/clone.sh
+++ b/examples/tools/clone.sh
@@ -15,8 +15,9 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
-# clone.sh <url> [to] [update]: clone into <root>/<folder>/<repo>, the folder
-# chosen by host from the clone-hosts map (github.com -> GITHUB, ...). An
+# clone.sh <url> [to] [update]: clone into <root>/<folder>/<owner>-<repo> (just
+# <repo> when the URL has no owner, or when owner and repo are the same), the
+# folder chosen by host from the clone-hosts map (github.com -> GITHUB, ...). An
# unknown host stops and says which folder to offer; passing that folder as
# <to> clones there and remembers the mapping. <update>=1 pulls an existing
# clone instead. Check: test-clone.sh.
@@ -56,12 +57,22 @@ host=${host%%:*}
path=${path%/}
repo=${path##*/}
repo=${repo%.git}
+# The segment before the repo is the owner; a nested group keeps only its last
+# segment. No slash at all means no owner.
+if [ "${path%/*}" = "$path" ]; then
+ owner=""
+else
+ owner=${path%/*}
+ owner=${owner##*/}
+fi
-# Both names land in a path, so neither may escape the tree.
+# Every name lands in a path, so none may escape the tree.
[[ $host =~ ^[A-Za-z0-9][A-Za-z0-9.-]*$ ]] ||
{ echo "bad host: $host" >&2; exit 1; }
[[ $repo =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ ]] ||
{ echo "bad repository name: $repo" >&2; exit 1; }
+[ -z "$owner" ] || [[ $owner =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ ]] ||
+ { echo "bad owner name: $owner" >&2; exit 1; }
# host -> folder, one tab-separated pair per line, seeded once. Appending the
# approved folder is how a new host is remembered, so the next clone of that
@@ -80,14 +91,17 @@ if [ -n "$to" ]; then
folder=$to
fi
+name=$repo
+[ -z "$owner" ] || [ "$owner" = "$repo" ] || name=$owner-$repo
+
if [ -z "$folder" ]; then
label=${host%.*}
label=$(printf '%s' "$label" | tr '[:lower:]' '[:upper:]')
- echo "no folder for host $host; ask the user: create $label/ and clone $repo there? if yes, call again with to=$label"
+ echo "no folder for host $host; ask the user: create $label/ and clone $name there? if yes, call again with to=$label"
exit 0
fi
-target=$root/$folder/$repo
+target=$root/$folder/$name
# Never clone over an existing folder, and never under another name: offer an
# update instead. ff-only so a diverged clone is reported, not merged.