Have git shim sync if necessary

This commit is contained in:
Max Howell 2023-10-31 10:41:13 -04:00
parent 7f51d21305
commit b2611e7df7
No known key found for this signature in database
GPG key ID: 741BB84EF5BB9EEC

View file

@ -18,13 +18,22 @@ libexec="$(cd "$(dirname "$0")/.." && pwd)"/libexec
# extract the git subcommand # extract the git subcommand
cmd=$(find_git_command "$@") 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 if [ -z "$cmd" ]; then
exec "$libexec/git" "$@" exec "$libexec/git" "$@"
elif [ -x "$libexec/git-$cmd" ] && [ -f "$libexec/git-$cmd" ]; then elif [ -x "$libexec/git-$cmd" ] && [ -f "$libexec/git-$cmd" ]; then
exec "$libexec/git" "$@" exec "$libexec/git" "$@"
elif type "git-$cmd" >/dev/null 2>&1; then elif type "git-$cmd" >/dev/null 2>&1; then
exec "$libexec/git" "$@" exec "$libexec/git" "$@"
elif command -v pkgx >/dev/null 2>&1 && pkg=$(pkgx --provider git-"$cmd"); then elif command -v pkgx >/dev/null 2>&1 && pkg=$(_provides); then
exec pkgx +"$pkg" "$libexec/git" "$@" exec pkgx +"$pkg" "$libexec/git" "$@"
else else
exec "$libexec/git" "$@" exec "$libexec/git" "$@"