forked from mirrors/jj
cli new: add --no-edit
option
This allows, for example, creating a merge commit with `jj new a b --no-edit -m Merge`, without affecting the working copy.
This commit is contained in:
parent
aa08de30c7
commit
e33f57a0f5
3 changed files with 57 additions and 5 deletions
|
@ -25,6 +25,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
usual behavior where commits that became unreachable in the Git repo are
|
||||
abandoned ([#2504](https://github.com/martinvonz/jj/pull/2504)).
|
||||
|
||||
* `jj new` gained a `--no-edit` option to prevent editing the newly created
|
||||
commit. For example, `jj new a b --no-edit -m Merge` creates a merge commit
|
||||
without affecting the working copy.
|
||||
|
||||
### Fixed bugs
|
||||
|
||||
|
||||
|
|
|
@ -27,7 +27,10 @@ use crate::cli_util::{
|
|||
};
|
||||
use crate::ui::Ui;
|
||||
|
||||
/// Create a new, empty change and edit it in the working copy
|
||||
/// Create a new, empty change and (by default) edit it in the working copy
|
||||
///
|
||||
/// By default, `jj` will edit the new change, making the working copy represent
|
||||
/// the new commit. This can be avoided with `--no-edit`.
|
||||
///
|
||||
/// Note that you can create a merge commit by specifying multiple revisions as
|
||||
/// argument. For example, `jj new main @` will create a new commit with the
|
||||
|
@ -50,6 +53,12 @@ pub(crate) struct NewArgs {
|
|||
/// Deprecated. Please prefix the revset with `all:` instead.
|
||||
#[arg(long, short = 'L', hide = true)]
|
||||
allow_large_revsets: bool,
|
||||
/// Do not edit the newly created change
|
||||
#[arg(long, conflicts_with = "_edit")]
|
||||
no_edit: bool,
|
||||
/// No-op flag to pair with --no-edit
|
||||
#[arg(long, hide = true)]
|
||||
_edit: bool,
|
||||
/// Insert the new change between the target commit(s) and their children
|
||||
//
|
||||
// Repeating this flag is allowed, but has no effect.
|
||||
|
@ -193,7 +202,9 @@ Please use `jj new 'all:x|y'` instead of `jj new --allow-large-revsets x y`.",
|
|||
if num_rebased > 0 {
|
||||
writeln!(ui.stderr(), "Rebased {num_rebased} descendant commits")?;
|
||||
}
|
||||
tx.edit(&new_commit).unwrap();
|
||||
if !args.no_edit {
|
||||
tx.edit(&new_commit).unwrap();
|
||||
}
|
||||
tx.finish(ui)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -42,6 +42,27 @@ fn test_new() {
|
|||
├─╯
|
||||
◉ 0000000000000000000000000000000000000000
|
||||
"###);
|
||||
|
||||
// --edit is a no-op
|
||||
test_env.jj_cmd_ok(&repo_path, &["new", "--edit", "-m", "yet another commit"]);
|
||||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
||||
@ 101cbec5cae8049cb9850a906ef3675631ed48fa yet another commit
|
||||
◉ 026537ddb96b801b9cb909985d5443aab44616c1 off of root
|
||||
│ ◉ 4f2d6e0a3482a6a34e4856a4a63869c0df109e79 a new commit
|
||||
│ ◉ 5d5c60b2aa96b8dbf55710656c50285c66cdcd74 add a file
|
||||
├─╯
|
||||
◉ 0000000000000000000000000000000000000000
|
||||
"###);
|
||||
|
||||
// --edit cannot be used with --no-edit
|
||||
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["new", "--edit", "B", "--no-edit", "D"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
error: the argument '--edit' cannot be used with '--no-edit'
|
||||
|
||||
Usage: jj new <REVISIONS>...
|
||||
|
||||
For more information, try '--help'.
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -71,11 +92,27 @@ fn test_new_merge() {
|
|||
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2"]);
|
||||
insta::assert_snapshot!(stdout, @"b");
|
||||
|
||||
// Same test with `--no-edit`
|
||||
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
||||
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["new", "main", "@", "--no-edit"]);
|
||||
// TODO(ilyagr): In this situation, `new` should probably report the identity of
|
||||
// the newly created commit.
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
insta::assert_snapshot!(stderr, @"");
|
||||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
||||
◉ 200ed1a14c8acf09783dafefe5bebf2ff58f12fd
|
||||
├─╮
|
||||
│ @ f399209d9dda06e8a25a0c8e9a0cde9f421ff35d add file2
|
||||
◉ │ 38e8e2f6c92ffb954961fc391b515ff551b41636 add file1
|
||||
├─╯
|
||||
◉ 0000000000000000000000000000000000000000
|
||||
"###);
|
||||
|
||||
// Same test with `jj merge`
|
||||
test_env.jj_cmd_ok(&repo_path, &["undo"]);
|
||||
test_env.jj_cmd_ok(&repo_path, &["merge", "main", "@"]);
|
||||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
||||
@ 200ed1a14c8acf09783dafefe5bebf2ff58f12fd
|
||||
@ 3a44e52b073cbb5deb11bb8fa0763a369e96427a
|
||||
├─╮
|
||||
│ ◉ f399209d9dda06e8a25a0c8e9a0cde9f421ff35d add file2
|
||||
◉ │ 38e8e2f6c92ffb954961fc391b515ff551b41636 add file1
|
||||
|
@ -94,9 +131,9 @@ fn test_new_merge() {
|
|||
"###);
|
||||
|
||||
// merge with non-unique revisions
|
||||
let stderr = test_env.jj_cmd_failure(&repo_path, &["new", "@", "200e"]);
|
||||
let stderr = test_env.jj_cmd_failure(&repo_path, &["new", "@", "3a44e"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: More than one revset resolved to revision 200ed1a14c8a
|
||||
Error: More than one revset resolved to revision 3a44e52b073c
|
||||
"###);
|
||||
|
||||
// merge with root
|
||||
|
|
Loading…
Reference in a new issue