-
Notifications
You must be signed in to change notification settings - Fork 752
cli: add --stdin and --edit flags to jj commit
#7714
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -568,18 +568,14 @@ fn test_commit_trailers() { | |
| "); | ||
|
|
||
| let editor0 = std::fs::read_to_string(test_env.env_root().join("editor0")).unwrap(); | ||
| 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. | ||
| "#); | ||
|
Comment on lines
-571
to
+578
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| let output = work_dir.run_jj(["log", "--no-graph", "-r@-", "-Tdescription"]); | ||
| insta::assert_snapshot!(output, @r" | ||
|
|
@@ -588,6 +584,92 @@ fn test_commit_trailers() { | |
| "); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_commit_with_description_from_stdin() { | ||
| let test_env = TestEnvironment::default(); | ||
| test_env.run_jj_in(".", ["git", "init", "repo"]).success(); | ||
| let work_dir = test_env.work_dir("repo"); | ||
|
|
||
| work_dir.write_file("file1", "foo\n"); | ||
| let output = work_dir | ||
| .run_jj_with(|cmd| { | ||
| cmd.args(["commit", "--stdin"]) | ||
| .write_stdin("Multi-line\n\ncommit message") | ||
| }) | ||
| .success(); | ||
| insta::assert_snapshot!(output); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use inline version: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you forgot to upload the latest change? |
||
|
|
||
| let output = work_dir.run_jj(["log", "--no-graph", "-r@-", "-Tdescription"]); | ||
| insta::assert_snapshot!(output); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_commit_with_empty_description_from_stdin() { | ||
| let test_env = TestEnvironment::default(); | ||
| test_env.run_jj_in(".", ["git", "init", "repo"]).success(); | ||
| let work_dir = test_env.work_dir("repo"); | ||
|
|
||
| work_dir.write_file("file1", "foo\n"); | ||
| let output = work_dir | ||
| .run_jj_with(|cmd| cmd.args(["commit", "--stdin"]).write_stdin("")) | ||
| .success(); | ||
| insta::assert_snapshot!(get_log_output(&work_dir)); | ||
| insta::assert_snapshot!(output); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_commit_with_description_from_stdin_and_edit() { | ||
| let mut test_env = TestEnvironment::default(); | ||
| let edit_script = test_env.set_up_fake_editor(); | ||
| test_env.run_jj_in(".", ["git", "init", "repo"]).success(); | ||
| let work_dir = test_env.work_dir("repo"); | ||
|
|
||
| work_dir.write_file("file1", "foo\n"); | ||
| std::fs::write(&edit_script, ["write\nedited message"].join("\0")).unwrap(); | ||
| work_dir | ||
| .run_jj_with(|cmd| { | ||
| cmd.args(["commit", "--stdin", "--edit"]) | ||
| .write_stdin("from stdin") | ||
| }) | ||
| .success(); | ||
|
|
||
| let output = work_dir.run_jj(["log", "--no-graph", "-r@-", "-Tdescription"]); | ||
| insta::assert_snapshot!(output); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_commit_stdin_conflicts_with_message() { | ||
| let test_env = TestEnvironment::default(); | ||
| test_env.run_jj_in(".", ["git", "init", "repo"]).success(); | ||
| let work_dir = test_env.work_dir("repo"); | ||
|
|
||
| let output = work_dir.run_jj_with(|cmd| { | ||
| cmd.args(["commit", "--stdin", "-m", "message"]) | ||
| .write_stdin("stdin") | ||
| }); | ||
| insta::assert_snapshot!(output); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_commit_stdin_with_interactive() { | ||
| let mut test_env = TestEnvironment::default(); | ||
| let diff_script = test_env.set_up_fake_diff_editor(); | ||
| test_env.run_jj_in(".", ["git", "init", "repo"]).success(); | ||
| let work_dir = test_env.work_dir("repo"); | ||
|
|
||
| work_dir.write_file("file1", "foo\n"); | ||
| std::fs::write(&diff_script, "dump JJ-INSTRUCTIONS instrs").unwrap(); | ||
| let output = work_dir | ||
| .run_jj_with(|cmd| { | ||
| cmd.args(["commit", "--stdin", "--interactive"]) | ||
| .write_stdin("from stdin") | ||
| }) | ||
| .success(); | ||
| insta::assert_snapshot!(output); | ||
| let log_output = work_dir.run_jj(["log", "--no-graph", "-r@-", "-Tdescription"]); | ||
| insta::assert_snapshot!(log_output); | ||
| } | ||
|
|
||
| #[must_use] | ||
| fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput { | ||
| let template = r#"commit_id.short() ++ " " ++ description"#; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll have to add
complete_newline()here. see #7837.