From 85a0f8857a1861dd9c8b3b8c37ecfc34242f7d8d Mon Sep 17 00:00:00 2001 From: Max Howell Date: Thu, 5 Oct 2023 13:52:36 -0400 Subject: [PATCH] `git foo` will automatically install and run `git-foo` (#3537) --- .vscode/settings.json | 1 - projects/git-scm.org/git-shim | 31 +++++++++++ projects/git-scm.org/package.yml | 94 ++++++++++++++++++-------------- 3 files changed, 84 insertions(+), 42 deletions(-) create mode 100755 projects/git-scm.org/git-shim diff --git a/.vscode/settings.json b/.vscode/settings.json index 89c517a3..e47dc085 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,4 @@ "deno.lint": true, "deno.unstable": true, "deno.config": ".github/deno.jsonc", - "deno.importMap": "../cli/import-map.json" } \ No newline at end of file diff --git a/projects/git-scm.org/git-shim b/projects/git-scm.org/git-shim new file mode 100755 index 00000000..4bb16020 --- /dev/null +++ b/projects/git-scm.org/git-shim @@ -0,0 +1,31 @@ +#!/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 "$@") + +if [ -z "$cmd" ]; then + exec "$libexec/git" "$@" +elif [ -x "$libexec/git-$_CMD" -a -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=$(pkgx --provider git-$cmd); then + exec pkgx +$pkg "$libexec/git" "$@" +else + exec "$libexec/git" "$@" +fi diff --git a/projects/git-scm.org/package.yml b/projects/git-scm.org/package.yml index edc17fae..3136bb7e 100644 --- a/projects/git-scm.org/package.yml +++ b/projects/git-scm.org/package.yml @@ -12,6 +12,7 @@ dependencies: curl.se/ca-certs: '*' perl.org: '*' libexpat.github.io: ~2 + pkgx.sh: ^1 runtime: env: @@ -19,65 +20,76 @@ runtime: GIT_SSL_CAINFO: ${{deps.curl.se/ca-certs.prefix}}/ssl/cert.pem build: - script: | - mv props/config.mak . + script: + - mv props/config.mak . - ./configure $CONF - make install $BAKE + - ./configure + --prefix={{ prefix }} + --with-perl={{ deps.perl.org.prefix }} + --with-gitconfig=etc/gitconfig - cd contrib/subtree - make - make install + - make install --jobs {{ hw.concurrency }} NO_TCLTK=1 - if test "{{ hw.platform }}" = "darwin"; then - cd "$SRCROOT/contrib/credential/osxkeychain" - make - mv git-credential-osxkeychain "{{prefix}}"/bin - make clean - cd "$SRCROOT/contrib/subtree" - fi + - run: | + make + make install + working-directory: contrib/subtree - mv git-subtree "{{prefix}}"/libexec + - run: | + make + mv git-credential-osxkeychain "{{prefix}}"/bin + make clean + working-directory: contrib/credential/osxkeychain + if: darwin - cd "{{prefix}}" - DEBUG=1 fix-shebangs.ts bin/* libexec/* + - run: mv git-subtree "{{prefix}}"/libexec + working-directory: contrib/subtree - mkdir -p etc - cp "$SRCROOT"/props/git* etc + - run: fix-shebangs.ts bin/* libexec/* + working-directory: ${{prefix}} + + - run: cp "$SRCROOT"/props/gitconfig "$SRCROOT"/props/gitignore . + working-directory: ${{prefix}}/etc + + - run: | + rm bin/git + cp $SRCROOT/props/git-shim bin/git + working-directory: ${{prefix}} env: V: 1 - BAKE: - - --jobs {{ hw.concurrency }} - - NO_TCLTK=1 - CONF: - - --prefix={{ prefix }} - - --with-perl={{ deps.perl.org.prefix }} - - --with-gitconfig=etc/gitconfig INSTALL_STRIP: -s -test: | - git clone https://github.com/teaxyz/white-paper 2>&1 | tee clone-output.txt +test: + # bug in pkgx where it doesn’t auto sync for --provides + - pkgx --sync # check that the templates can be found - if grep -q 'warning: templates not found in' clone-output.txt; then - false - fi + - run: | + git clone https://github.com/teaxyz/white-paper 2>&1 | tee clone-output.txt + if grep -q 'warning: templates not found in' clone-output.txt; then + exit 1 + fi + working-directory: $(mktemp -d) - mkdir foo - cd foo - touch .DS_Store testfile - git init - git add . - test "$(git diff --name-only --cached)" = "testfile" + - cd $(mktemp -d) + + - run: | + touch .DS_Store testfile + git init + git add . + test "$(git diff --name-only --cached)" = "testfile" # necessary so `git commit` will work - git config user.email "you@example.com" - git config user.name "Your Name" + - | + git config user.email "you@example.com" + git config user.name "Your Name" # necessary to check the libexec binaries work - git commit --message "test" + - git commit --message "test" - git subtree add --prefix teaxyz-subtree https://github.com/teaxyz/white-paper main --squash + - git subtree add --prefix teaxyz-subtree https://github.com/teaxyz/white-paper main --squash + + - git gone --version provides: linux: