Skip to content

Conversation

tekacs
Copy link

@tekacs tekacs commented Oct 13, 2025

Add --stdin flag to read commit messages from stdin, matching the existing pattern in jj describe. This solves the problem of passing multi-line commit messages from scripts and the command line without shell escaping issues.

Add --edit flag to allow opening an editor after providing a message via --stdin or -m, enabling users to refine messages in two stages.

Implementation:

  • Added proper conflicts: --stdin cannot be used with -m, --interactive, or --tool
  • Restructured description handling to check stdin first, then -m flags, then fall back to editor
  • Introduced use_editor variable to control editor invocation
  • Trailers are properly handled in all code paths

This brings jj commit to feature parity with jj describe for message input methods.

Checklist

  • Added CHANGELOG entry
  • Added comprehensive tests for stdin functionality
  • All existing tests pass

@tekacs tekacs requested a review from a team as a code owner October 13, 2025 06:43
Copy link

google-cla bot commented Oct 13, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@tekacs
Copy link
Author

tekacs commented Oct 13, 2025

Signed the CLA

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

The following commits do not follow our format for subject lines:

  • c9d9117: Merge branch 'main' into commit-stdin-flag

Commits should have a subject line following the format <topic>: <description>. Please review the commit guidelines for more information.

@tekacs tekacs force-pushed the commit-stdin-flag branch from c9d9117 to e23d47a Compare October 15, 2025 10:28
@github-actions github-actions bot dismissed their stale review October 15, 2025 10:28

All commits are now correctly formatted. Thank you for your contribution!

Copy link
Contributor

@yuja yuja left a comment

Choose a reason for hiding this comment

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

Thanks.

let output = work_dir
.run_jj_with(|cmd| cmd.args(["commit", "--stdin"]).write_stdin("Multi-line\n\ncommit message"))
.success();
insta::assert_snapshot!(output);
Copy link
Contributor

Choose a reason for hiding this comment

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

use inline version: insta::assert_snapshot!(output, @"");

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you forgot to upload the latest change?

Add `--stdin` flag to read commit messages from stdin, matching the
existing pattern in `jj describe`. This solves the problem of passing
multi-line commit messages from scripts and the command line without
shell escaping issues.

Add `--edit` flag to allow opening an editor after providing a message
via `--stdin` or `-m`, enabling users to refine messages in two stages.

Implementation:
- Added proper conflicts: `--stdin` cannot be used with `-m`,
  `--interactive`, or `--tool`
- Restructured description handling to check stdin first, then -m
  flags, then fall back to editor
- Introduced `use_editor` variable to control editor invocation
- Trailers are properly handled in all code paths

This brings `jj commit` to feature parity with `jj describe` for
message input methods.

Updates:
- Added CHANGELOG entry
- Added comprehensive tests for stdin functionality
- All existing tests pass
@tekacs tekacs force-pushed the commit-stdin-flag branch from e23d47a to 292a096 Compare October 16, 2025 07:59
@tekacs
Copy link
Author

tekacs commented Oct 16, 2025

Comments should be resolved!

Comment on lines -571 to +578
insta::assert_snapshot!(
format!("-----\n{editor0}-----\n"), @r#"
-----
insta::assert_snapshot!(editor0, @r#"
Reviewed-by: [email protected]
Reviewed-by: [email protected]
JJ: Change ID: zsuskuln
JJ:
JJ: Lines starting with "JJ:" (like this one) will be removed.
-----
"#);
JJ: Change ID: zsuskuln
JJ:
JJ: Lines starting with "JJ:" (like this one) will be removed.
"#);
Copy link
Contributor

Choose a reason for hiding this comment

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

Revert this change. I think the intent here is to ensure that the editor content is terminated by \n. insta::assert_snapshot!() isn't strict about leading/trailing newlines.

let output = work_dir
.run_jj_with(|cmd| cmd.args(["commit", "--stdin"]).write_stdin("Multi-line\n\ncommit message"))
.success();
insta::assert_snapshot!(output);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you forgot to upload the latest change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants