Skip to content

Commit 89c216e

Browse files
feat(record): allow multiple --message args
this works, right?
1 parent 81e298d commit 89c216e

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-branchless-opts/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ pub struct RecordArgs {
300300
/// The commit message to use. If not provided, will be prompted to provide a commit message
301301
/// interactively.
302302
#[clap(value_parser, short = 'm', long = "message")]
303-
pub message: Option<String>,
303+
pub messages: Vec<String>,
304304

305305
/// Select changes to include interactively, rather than using the
306306
/// current staged/unstaged changes.

git-branchless-record/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ tracing = { workspace = true }
2222

2323
[dev-dependencies]
2424
insta = { workspace = true }
25+
regex = { workspace = true }

git-branchless-record/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn command_main(ctx: CommandContext, args: RecordArgs) -> EyreExitOr<()> {
5252
git_run_info,
5353
} = ctx;
5454
let RecordArgs {
55-
message,
55+
messages,
5656
interactive,
5757
create,
5858
detach,
@@ -61,7 +61,7 @@ pub fn command_main(ctx: CommandContext, args: RecordArgs) -> EyreExitOr<()> {
6161
record(
6262
&effects,
6363
&git_run_info,
64-
message,
64+
messages,
6565
interactive,
6666
create,
6767
detach,
@@ -73,7 +73,7 @@ pub fn command_main(ctx: CommandContext, args: RecordArgs) -> EyreExitOr<()> {
7373
fn record(
7474
effects: &Effects,
7575
git_run_info: &GitRunInfo,
76-
message: Option<String>,
76+
messages: Vec<String>,
7777
interactive: bool,
7878
branch_name: Option<String>,
7979
detach: bool,
@@ -150,15 +150,15 @@ fn record(
150150
&repo,
151151
&snapshot,
152152
event_tx_id,
153-
message.as_deref(),
153+
messages,
154154
)?);
155155
}
156156
} else {
157157
let args = {
158158
let mut args = vec!["commit"];
159-
if let Some(message) = &message {
160-
args.extend(["--message", message]);
161-
}
159+
messages
160+
.iter()
161+
.for_each(|message| args.extend(["--message", message]));
162162
if working_copy_changes_type == WorkingCopyChangesType::Unstaged {
163163
args.push("--all");
164164
}
@@ -227,7 +227,7 @@ fn record_interactive(
227227
repo: &Repo,
228228
snapshot: &WorkingCopySnapshot,
229229
event_tx_id: EventTransactionId,
230-
message: Option<&str>,
230+
messages: Vec<String>,
231231
) -> EyreExitOr<()> {
232232
let old_tree = snapshot.commit_stage0.get_tree()?;
233233
let new_tree = snapshot.commit_unstaged.get_tree()?;
@@ -246,7 +246,7 @@ fn record_interactive(
246246
is_read_only: false,
247247
commits: vec![
248248
Commit {
249-
message: Some(message.map(|s| s.to_owned()).unwrap_or_default()),
249+
message: Some(messages.iter().join("\n\n")),
250250
},
251251
Commit { message: None },
252252
],

git-branchless-record/tests/test_record.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use lib::testing::pty::{run_in_pty, PtyAction, DOWN_ARROW};
22
use lib::testing::{make_git, GitInitOptions, GitRunOptions};
3+
use regex::Regex;
34

45
#[test]
56
fn test_record_unstaged_changes() -> eyre::Result<()> {
@@ -13,22 +14,31 @@ fn test_record_unstaged_changes() -> eyre::Result<()> {
1314
git.commit_file("test1", 1)?;
1415
git.write_file_txt("test1", "contents1\n")?;
1516
{
16-
let (stdout, _stderr) = git.branchless("record", &["-m", "foo"])?;
17+
let (stdout, _stderr) = git.branchless("record", &["-m", "foo", "-m", "bar"])?;
1718
insta::assert_snapshot!(stdout, @r###"
18-
[master 914812a] foo
19+
[master 872eae1] foo
1920
1 file changed, 1 insertion(+), 1 deletion(-)
2021
"###);
2122
}
2223

2324
{
2425
let (stdout, _stderr) = git.run(&["show"])?;
25-
insta::assert_snapshot!(stdout, @r###"
26-
commit 914812ae3220add483f11d851dc59f0b5dbdeaa0
26+
// For the empty lines between paragraphs, git show prints 4 spaces
27+
// instead of just an empty line. (ie " \n" instead of "\n") It's
28+
// hard to work with this in an inline snapshot, as editors often trim
29+
// trailing whitespace, so here we just modify the output (by replacing
30+
// any such lines) to make it easier to assert against with insta
31+
let whitespace_only_line_regex = Regex::new(r"(?m)^ {4}$").unwrap();
32+
let trimmed_stdout = whitespace_only_line_regex.replace_all(&stdout, "");
33+
insta::assert_snapshot!(trimmed_stdout, @r###"
34+
commit 872eae10daf1e94d0c346540f6d655027c60e7ae
2735
Author: Testy McTestface <test@example.com>
2836
Date: Thu Oct 29 12:34:56 2020 +0000
2937
3038
foo
3139
40+
bar
41+
3242
diff --git a/test1.txt b/test1.txt
3343
index 7432a8f..a024003 100644
3444
--- a/test1.txt

0 commit comments

Comments
 (0)