pantry/projects/git-scm.org/git-shim
2023-10-31 10:41:13 -04:00

41 lines
814 B
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
set -e
find_git_command() {
for arg in "$@"; do
case $arg in
-*);;
*)
echo "$arg"
return # found the command!
esac
done
}
libexec="$(cd "$(dirname "$0")/.." && pwd)"/libexec
# extract the git subcommand
cmd=$(find_git_command "$@")
_provides() {
if foo="$(pkgx --provider git-"$cmd")"; then
echo "$foo"
else
# syncing is slow but lets be sure about it
pkgx --sync --provider git-"$cmd"
fi
}
if [ -z "$cmd" ]; then
exec "$libexec/git" "$@"
elif [ -x "$libexec/git-$cmd" ] && [ -f "$libexec/git-$cmd" ]; then
exec "$libexec/git" "$@"
elif type "git-$cmd" >/dev/null 2>&1; then
exec "$libexec/git" "$@"
elif command -v pkgx >/dev/null 2>&1 && pkg=$(_provides); then
exec pkgx +"$pkg" "$libexec/git" "$@"
else
exec "$libexec/git" "$@"
fi