2023-10-05 20:52:36 +03:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
2023-11-19 00:11:49 +03:00
|
|
|
|
# This function searches through the provided arguments
|
|
|
|
|
# to find the first non-option argument, which is assumed
|
|
|
|
|
# to be the git subcommand.
|
|
|
|
|
find_git_subcommand() {
|
|
|
|
|
skip_next=0 # Flag to indicate if the next argument should be skipped.
|
|
|
|
|
|
2023-10-05 20:52:36 +03:00
|
|
|
|
for arg in "$@"; do
|
2023-11-19 00:11:49 +03:00
|
|
|
|
# If the skip_next flag is set, skip this argument.
|
|
|
|
|
if [ "$skip_next" -eq 1 ]; then
|
|
|
|
|
skip_next=0
|
2023-11-14 22:31:33 +03:00
|
|
|
|
continue
|
|
|
|
|
fi
|
2023-11-19 00:11:49 +03:00
|
|
|
|
|
|
|
|
|
# Check for options that require skipping the next argument.
|
2023-10-05 20:52:36 +03:00
|
|
|
|
case $arg in
|
2023-11-19 00:11:49 +03:00
|
|
|
|
-C | --git-dir | --work-tree | --namespace | --super-prefix | --config-env | -c)
|
|
|
|
|
skip_next=1 # The next argument is a value for these options.
|
|
|
|
|
continue
|
|
|
|
|
;;
|
|
|
|
|
-*)
|
|
|
|
|
continue # Skip other options that start with '-'.
|
|
|
|
|
;;
|
2023-10-05 20:52:36 +03:00
|
|
|
|
esac
|
2023-11-19 00:11:49 +03:00
|
|
|
|
|
|
|
|
|
# If we reach this point, it's likely the git subcommand.
|
|
|
|
|
echo "$arg"
|
|
|
|
|
return
|
2023-10-05 20:52:36 +03:00
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
libexec="$(cd "$(dirname "$0")/.." && pwd)"/libexec
|
|
|
|
|
|
|
|
|
|
# extract the git subcommand
|
2023-11-19 00:11:49 +03:00
|
|
|
|
cmd=$(find_git_subcommand "$@")
|
2023-10-05 20:52:36 +03:00
|
|
|
|
|
2023-10-31 17:41:13 +03:00
|
|
|
|
_provides() {
|
|
|
|
|
if foo="$(pkgx --provider git-"$cmd")"; then
|
|
|
|
|
echo "$foo"
|
|
|
|
|
else
|
|
|
|
|
# syncing is slow but let’s be sure about it
|
|
|
|
|
pkgx --sync --provider git-"$cmd"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-05 20:52:36 +03:00
|
|
|
|
if [ -z "$cmd" ]; then
|
|
|
|
|
exec "$libexec/git" "$@"
|
2023-10-07 05:57:28 +03:00
|
|
|
|
elif [ -x "$libexec/git-$cmd" ] && [ -f "$libexec/git-$cmd" ]; then
|
2023-10-05 20:52:36 +03:00
|
|
|
|
exec "$libexec/git" "$@"
|
|
|
|
|
elif type "git-$cmd" >/dev/null 2>&1; then
|
|
|
|
|
exec "$libexec/git" "$@"
|
2023-10-31 17:41:13 +03:00
|
|
|
|
elif command -v pkgx >/dev/null 2>&1 && pkg=$(_provides); then
|
2023-10-07 05:57:28 +03:00
|
|
|
|
exec pkgx +"$pkg" "$libexec/git" "$@"
|
2023-10-05 20:52:36 +03:00
|
|
|
|
else
|
|
|
|
|
exec "$libexec/git" "$@"
|
|
|
|
|
fi
|