From 3f10e70ff9e0a582257b46318f02c45b1e278101 Mon Sep 17 00:00:00 2001 From: Waleed Khan Date: Mon, 21 Aug 2023 16:22:45 -0700 Subject: [PATCH] command: add `--interactive` flag to `jj commit` --- cli/src/commands/mod.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs index 3c8b0094e0..f825c36a81 100644 --- a/cli/src/commands/mod.rs +++ b/cli/src/commands/mod.rs @@ -467,6 +467,9 @@ struct DescribeArgs { #[derive(clap::Args, Clone, Debug)] #[command(visible_aliases=&["ci"])] struct CommitArgs { + /// Interactively choose which changes to commit + #[arg(short, long)] + interactive: bool, /// The change description to use (don't open editor) #[arg(long = "message", short, value_name = "MESSAGE")] message_paragraphs: Vec, @@ -2046,6 +2049,7 @@ fn cmd_describe( #[instrument(skip_all)] fn cmd_commit(ui: &mut Ui, command: &CommandHelper, args: &CommitArgs) -> Result<(), CommandError> { let CommitArgs { + interactive, message_paragraphs, paths, } = args; @@ -2060,7 +2064,24 @@ fn cmd_commit(ui: &mut Ui, command: &CommandHelper, args: &CommitArgs) -> Result let matcher = workspace_command.matcher_from_values(paths)?; let mut tx = workspace_command.start_transaction(&format!("commit {}", commit.id().hex())); let base_tree = merge_commit_trees(tx.repo(), &commit.parents())?; - let tree_id = tx.select_diff(ui, &base_tree, &commit.tree(), matcher.as_ref(), "", false)?; + let instructions = format!( + "\ +You are making a partial commit from the changes in: {} + +The diff initially shows all changes. Adjust the right side until it shows the +contents you want for the new commit. The remainder will stay in the working +copy. +", + tx.format_commit_summary(&commit) + ); + let tree_id = tx.select_diff( + ui, + &base_tree, + &commit.tree(), + matcher.as_ref(), + &instructions, + *interactive, + )?; let middle_tree = tx.repo().store().get_tree(&RepoPath::root(), &tree_id)?; if !paths.is_empty() && middle_tree.id() == base_tree.id() { writeln!(