8000 commands: add -m to `jj merge` and `jj close` · Pulkit07/jj@37a2fbc · GitHub
[go: up one dir, main page]

Skip to content

Commit 37a2fbc

Browse files
committed
commands: add -m to jj merge and jj close
1 parent c459c61 commit 37a2fbc

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

src/commands.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ fn rev_arg<'a, 'b>() -> Arg<'a, 'b> {
184184
.default_value("@")
185185
}
186186

187+
fn message_arg<'a, 'b>() -> Arg<'a, 'b> {
188+
Arg::with_name("message")
189+
.long("message")
190+
.short("m")
191+
.takes_value(true)
192+
}
193+
187194
fn op_arg<'a, 'b>() -> Arg<'a, 'b> {
188195
Arg::with_name("operation")
189196
.long("operation")
@@ -335,16 +342,12 @@ fn get_app<'a, 'b>() -> App<'a, 'b> {
335342
let describe_command = SubCommand::with_name("describe")
336343
.about("edit the commit description")
337344
.arg(rev_arg())
338-
.arg(
339-
Arg::with_name("message")
340-
.long("message")
341-
.short("m")
342-
.takes_value(true),
343-
)
345+
.arg(message_arg())
344346
.arg(Arg::with_name("stdin").long("stdin"));
345347
let close_command = SubCommand::with_name("close")
346348
.about("mark a commit closed, making new work go into a new commit")
347-
.arg(rev_arg());
349+
.arg(rev_arg())
350+
.arg(message_arg());
348351
let open_command = SubCommand::with_name("open")
349352
.about("mark a commit open, making new work be added to it")
350353
.arg(rev_arg());
@@ -394,7 +397,8 @@ fn get_app<'a, 'b>() -> App<'a, 'b> {
394397
.index(1)
395398
.required(true)
396399
.multiple(true),
397-
);
400+
)
401+
.arg(message_arg());
398402
let rebase_command = SubCommand::with_name("rebase")
399403
.about("move a commit to a different parent")
400404
.arg(rev_arg())
@@ -1246,10 +1250,15 @@ fn cmd_close(
12461250
let commit = resolve_revision_arg(ui, mut_repo, sub_matches)?;
12471251
let mut commit_builder =
12481252
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit).set_open(false);
1249-
if commit.description().is_empty() {
1250-
let description = edit_description(&repo, commit.description());
1251-
commit_builder = commit_builder.set_description(description);
1253+
let description;
1254+
if sub_matches.is_present("message") {
1255+
description = sub_matches.value_of("message").unwrap().to_string();
1256+
} else if commit.description().is_empty() {
1257+
description = edit_description(&repo, "");
1258+
} else {
1259+
description = commit.description().to_string();
12521260
}
1261+
commit_builder = commit_builder.set_description(description);
12531262
let mut tx = repo.start_transaction(&format!("close commit {}", commit.id().hex()));
12541263
commit_builder.write_to_transaction(&mut tx);
12551264
update_checkout_after_rewrite(ui, &mut tx);
@@ -1562,7 +1571,12 @@ fn cmd_merge(
15621571
parent_ids.push(commit.id().clone());
15631572
commits.push(commit);
15641573
}
1565-
let description = edit_description(&repo, "");
1574+
let description;
1575+
if sub_matches.is_present("message") {
1576+
description = sub_matches.value_of("message").unwrap().to_string();
1577+
} else {
1578+
description = edit_description(&repo, "");
1579+
}
15661580
let merged_tree = merge_commit_trees(repo.store(), &commits);
15671581
let mut tx = repo.start_transaction("merge commits");
15681582
CommitBuilder::for_new_commit(ui.settings(), repo.store(), merged_tree.id().clone())

0 commit comments

Comments
 (0)
0