From 2212db947c1d720315e2b33913d483d422bf39ce Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Sun, 27 Apr 2025 10:33:41 +0000 Subject: [PATCH] JP CLI: add support for git command passthrough --- projects/js-packages/jetpack-cli/bin/jp.js | 18 ++++++++++++++++++ .../changelog/add-jp-git-passthrough | 4 ++++ tools/docker/bin/monorepo | 8 ++++++++ 3 files changed, 30 insertions(+) create mode 100644 projects/js-packages/jetpack-cli/changelog/add-jp-git-passthrough diff --git a/projects/js-packages/jetpack-cli/bin/jp.js b/projects/js-packages/jetpack-cli/bin/jp.js index 80da9dc157f31..39466b316a983 100755 --- a/projects/js-packages/jetpack-cli/bin/jp.js +++ b/projects/js-packages/jetpack-cli/bin/jp.js @@ -306,6 +306,24 @@ const main = async () => { } } + // Handle git passthrough: run git commands inside the container for pre-commit hooks, etc. + if ( args[ 0 ] === 'git' ) { + // This allows: jp git commit -m "msg" (runs inside container, so hooks/tools are consistent) + // Always disable GPG signing in the container to avoid missing key errors. + const result = spawnSync( + resolve( monorepoRoot, 'tools/docker/bin/monorepo' ), + [ 'git', '-c', 'commit.gpgSign=false', ...args.slice( 1 ) ], + { + stdio: 'inherit', + cwd: monorepoRoot, + } + ); + if ( result.status !== 0 ) { + throw new Error( `Git command failed with status ${ result.status }` ); + } + return; + } + // Run the monorepo script with the original arguments const result = spawnSync( resolve( monorepoRoot, 'tools/docker/bin/monorepo' ), diff --git a/projects/js-packages/jetpack-cli/changelog/add-jp-git-passthrough b/projects/js-packages/jetpack-cli/changelog/add-jp-git-passthrough new file mode 100644 index 0000000000000..ef68b48a35048 --- /dev/null +++ b/projects/js-packages/jetpack-cli/changelog/add-jp-git-passthrough @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Add support for git command passthrough diff --git a/tools/docker/bin/monorepo b/tools/docker/bin/monorepo index 8a6cc39d39c8d..07bbe97498734 100755 --- a/tools/docker/bin/monorepo +++ b/tools/docker/bin/monorepo @@ -36,6 +36,13 @@ if ! docker image inspect jetpack-monorepo:latest >/dev/null 2>&1; then fi fi +# If the user's .gitconfig exists, mount it into the container for git passthrough commands (jp git ...) +if [ -f "$HOME/.gitconfig" ]; then + GITCONFIG_MOUNT="-v $HOME/.gitconfig:/root/.gitconfig:ro" +else + GITCONFIG_MOUNT="" +fi + # Run the command in the container docker run --rm -it \ -v "$MONOREPO_ROOT:/workspace" \ @@ -51,5 +58,6 @@ docker run --rm -it \ -e NPM_CONFIG_CACHE=/root/.npm \ -e PNPM_HOME=/root/.local/share/pnpm \ -e PNPM_STORE_DIR=/root/.pnpm-store \ + $GITCONFIG_MOUNT \ jetpack-monorepo:latest \ "$@"