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

Conversation

kraftbj
Copy link
Contributor

@kraftbj kraftbj commented Apr 27, 2025

I realize this may not be the ideal approach. :)

The problem: The jp command uses a docker container for running development commands to avoid needing your machine to have the right versions of everything.

This works fairly well for all commands in the jetpack CLI; however, we expect precommit and prepush hooks to run, which currently are on the local machine. So, we still need things setup right on the local machine.

The solution: This adds a jp git command that passes through to git on the developer container, where node, etc are all set.

Nuance: my gitconfig file has me sign everything by default, but for this iteration, I didn't want to handle some type of key forwarding (which doesn't natively exist like ssh -A). In this initial iteration, just ensure we don't try to sign things.

Proposed changes:

  • Pass jp git commands to git on the dev container.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

n/a

Does this pull request change what data or activity we track or use?

no

Testing instructions:

  • ./projects/js-packages/jetpack-cli/bin/jp.js --help [ensure the default behavior works, passing to jetpack
  • ./projects/js-packages/jetpack-cli/bin/jp.js git status [ensures git works]
  • ./projects/js-packages/jetpack-cli/bin/jp.js install -r [install monorepo root, just in case it hasn't been done]
  • ./projects/js-packages/jetpack-cli/bin/jp.js git commit -a -m "test test test" [after making some local changes, namely to php and js files to let phpcbf, prettier, etc run on precommit]

The following will not yet work and will need a follow-up PR.

  • ./projects/js-packages/jetpack-cli/bin/jp.js git push [need to get key support working]
  • ./projects/js-packages/jetpack-cli/bin/jp.js git commit -a [where it needs to prompt you for the commit messages. to get a quoted string to work, I disabled shell, but that breaks the editor prompt. Will aim to figure this out in a follow-up.

@kraftbj kraftbj added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review This PR is ready for review. labels Apr 27, 2025
@kraftbj kraftbj requested review from a team April 27, 2025 10:48
Copy link
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

Copy link
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like about as good as we can do for this approach. While it should work for most people, you did already have to include a hack for commit signing and there are probably other things that'd break too. For example, my ~/.gitconfig has a bit like this

[includeIf "gitdir:/usr/local/src/automattic/"]
	path = /usr/local/src/automattic/.gitconfig

and that file, among other things, overrides user.email from my personal email to my work email.

While that's not necessarily a show-stopper here, I wonder if we'd do better to change the hooks themselves to run the node bits inside the container via jp if the jp command is available (i.e. if command -v jp &>/dev/null; then).

@tbradsha
Copy link
Contributor

tbradsha commented Apr 28, 2025

I wonder if we'd do better to change the hooks themselves to run the node bits inside the container

This is the approach we discussed elsewhere (p1743513123465659/1743454819.828509-slack-C05Q5HSS013); I'd personally prefer that route.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docker [JS Package] Jetpack CLI RNA [Status] Needs Review This PR is ready for review. [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants