Skip to content

JP CLI: add support for git command passthrough #43258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions projects/js-packages/jetpack-cli/bin/jp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Add support for git command passthrough
8 changes: 8 additions & 0 deletions tools/docker/bin/monorepo
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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 \
"$@"
Loading