#!/bin/sh
-if [ $# -lt 2 ] || [ $# -gt 3 ]; then
- printf 'usage: %s <remote name> <url> [<branch>]\n' "$0" 1>&2
+if [ $# -lt 3 ] || [ $# -gt 4 ]; then
+ printf 'usage: %s <contacts> <remote name> <url> [<branch>]\n' "$0" 1>&2
exit 1
fi
-name="$1"
-url="$2"
-branch="$3"
+contacts="$1"
+name="$2"
+url="$3"
+branch="$4"
+if [ -z "$contacts" ]; then
+ printf 'Need contacts\n' 1>&2
+ exit 1
+fi
if [ -z "$name" ]; then
printf 'Need a remote name\n' 1>&2
exit 1
branch='master'
fi
-if git remote add --no-tags -t "$branch" "$name" "$url"; then
- cp .git/config ../etc/git-config
+url=$(printf '%s\n' "$url" | sed -Ee '
+ s,^(git|https)://git.kernel.org/pub/scm/linux/kernel/git/,korg:,
+ s,^(git|https)://git.kernel.org/pub/scm/fs/,korgfs:,
+ s,^git://git.infradead.org/,id:,
+ s,^https://github.com/,gh:,
+ s,^https://gitlab.freedesktop.org/,gfo:,
+ s,/$,,')
+
+if ! git remote add --no-tags -t "$branch" "$name" "$url"; then
+ exit 1
fi
+cp .git/config ../etc/git-config
+
+cd ../etc/
+
+printf '%s\tgit\t%s\t-\t%s\tno\n' "$contacts" "$name" "$branch" >>../etc/control
+
+git diff
+
+printf '\nYou should probably adjust where this tree is listed in the control file\n'
+
exit 0