config/git: improve hook and scripts

This commit is contained in:
xeruf 2022-08-21 12:29:51 +02:00
parent e4e1ef292e
commit 0b08febafd
4 changed files with 32 additions and 27 deletions

View File

@ -119,10 +119,10 @@
# diffs
d = diff
dm = !git diff $(git merge-base $(git main) HEAD)
dw = diff --color-words
dc = diff --color-words="[^[:space:]]|([[:alnum:]]|UTF_8_GUARD)+"
du = diff @{push}
dm = !git diff $(git merge-base $(git main) HEAD) # [d]iff to [m]ain
dw = diff --color-words # [d]iff [w]ords
dc = diff --color-words="[^[:space:]]|([[:alnum:]]|UTF_8_GUARD)+" # [d]iff [c]haracters
du = diff @{push} # [d]iff [u]pstream
# MODIFY

View File

@ -25,10 +25,9 @@ if beginswith $'\n#' "$original"; then
done
done <<<"$(git -P diff --cached --name-only -r)" &&
expr substr "$common" 1 "$count" | sed 's|.local/bin/scripts|bin|') || exit 0
case "$path" in ([0-9]*) path="${path#*/}";; esac
path="${path#.}"
case "$path" in ([0-9]-*) path="${path#*-}";; esac
{
echo "${path%-}:"
echo "$path" | sed 's|^\.||;s|/\?$|: |'
echo "$original"
} > "$COMMIT_MSG_FILE"
fi

View File

@ -1,6 +1,6 @@
#!/bin/sh -ex
#!/bin/sh -e
# Clones from resolving the arguments and switches into the new directory
# ARGS see git-repo, all arguments beyond the first three are forwarded to git-clone
# ARGS: see git-repo, all arguments beyond the first three are forwarded to git clone
remote=$(git-repo "$@")
echo "Cloning $remote"
test $1 = https && shift
@ -14,7 +14,8 @@ case $# in
(*) dir="${prefix}_$2";;
esac;;
esac
shift $(expr $# \& $# \< 3 \| 3)
case "$4" in (-*|"") cdir="$2";; (*) cdir="$4";; esac
shift $(expr 3 \& $# \> 3 \| $#)
git clone $remote "$@" $dir --recurse-submodules
cd "${dir:-${4:-$2}}"
cd "${dir:-$cdir}"
exec

View File

@ -3,21 +3,26 @@
# Usage:
# git repo <url>
# git repo <host> <repo> [user]
test "$1" = https && https=true && shift
case "$1" in
(http*) echo "$1" | sed "s|.*//\([^/]*\)/\(.*\)|git@\1:\2.git|" ;;
(git:*|ssh:*) echo "$1" ;;
(*)
case $1 in
(socha) user=software-challenge; host=git@github.com;;
(hub) host=git@github.com;;
(lab) host=git@gitlab.com;;
(*) host=${1:-gitea@git.jfischer.org};;
esac
user=${3:-${user:-$(git config user.name)}}
repo=${2:-$(basename $PWD)}
if test "$https"
then echo "https://${host#git*@}/$user/$repo.git"
else echo "$host:$user/$repo.git"
fi
(http*)
if expr "$1" : ".*:" >/dev/null
then echo "$1" | sed "s|.*//\([^/]*\)/\(.*\)|git@\1:\2.git|"
exit
else http=$1 && shift
fi;;
(git:*|ssh:*)
echo "$1"
exit;;
esac
case $1 in
(socha) user=software-challenge; host=git@github.com;;
(hub) host=git@github.com;;
(lab) host=git@gitlab.com;;
(*) host=${1:-gitea@git.jfischer.org};;
esac
user=${3:-${user:-$(git config user.name)}}
repo=${2:-$(basename $PWD)}
if test "$http"
then echo "$http://${host#git*@}/$user/$repo.git"
else echo "$host:$user/$repo.git"
fi