Skip to content

Commit 81cf50a

Browse files
feat(record): allow multiple --message args
1 parent 20f18c7 commit 81cf50a

File tree

5 files changed

+33
-13
lines changed

5 files changed

+33
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
- BREAKING (#1128) Arguments/revsets passed to `git sync` are now resolved to their respective stacks.
1919
- This allows `git sync my-branch` to work as expected, instead of needing to use `git sync 'stack(my-branch)'`. The behavior of `git sync` when called without arguments is not affected by this change. If you rely on the previous behavior, please use `git move -x <commit(s)/revset> -d 'main()'` instead.
20+
- (#1169) `git record` now accepts multible `--message` arguments.
2021

2122
### Fixed
2223

git-branchless-lib/src/testing.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,25 @@ impl Git {
129129
})
130130
.into_owned();
131131

132+
lazy_static! {
133+
// Convert non-empty, blank lines to empty, blank lines to make the
134+
// command output easier to use in snapshot assertions.
135+
//
136+
// Some git output includes lines made up of only whitespace, which
137+
// is hard to work with as inline snapshots because editors often
138+
// trim such trailing whitespace automatically. In particular,
139+
// `git show` prints 4 spaces instead of just an empty line for the
140+
// lines between commit message paragraphs. (ie " \n" instead of
141+
// just "\n".)
142+
//
143+
// This regex targets the output of `git show`, but it could be
144+
// generalized in the future if other cases come up.
145+
static ref WHITESPACE_ONLY_LINE_RE: Regex = Regex::new(r"(?m)^ {4}$").unwrap();
146+
}
147+
let output = WHITESPACE_ONLY_LINE_RE
148+
.replace_all(&output, "")
149+
.into_owned();
150+
132151
Ok(output)
133152
}
134153

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/src/lib.rs

Lines changed: 7 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,
@@ -62,7 +62,7 @@ pub fn command_main(ctx: CommandContext, args: RecordArgs) -> EyreExitOr<()> {
6262
record(
6363
&effects,
6464
&git_run_info,
65-
message,
65+
messages,
6666
interactive,
6767
create,
6868
detach,
@@ -75,7 +75,7 @@ pub fn command_main(ctx: CommandContext, args: RecordArgs) -> EyreExitOr<()> {
7575
fn record(
7676
effects: &Effects,
7777
git_run_info: &GitRunInfo,
78-
message: Option<String>,
78+
messages: Vec<String>,
7979
interactive: bool,
8080
branch_name: Option<String>,
8181
detach: bool,
@@ -153,15 +153,13 @@ fn record(
153153
&repo,
154154
&snapshot,
155155
event_tx_id,
156-
message.as_deref(),
156+
messages,
157157
)?);
158158
}
159159
} else {
160160
let args = {
161161
let mut args = vec!["commit"];
162-
if let Some(message) = &message {
163-
args.extend(["--message", message]);
164-
}
162+
args.extend(messages.iter().flat_map(|message| ["--message", message]));
165163
if working_copy_changes_type == WorkingCopyChangesType::Unstaged {
166164
args.push("--all");
167165
}
@@ -256,7 +254,7 @@ fn record_interactive(
256254
repo: &Repo,
257255
snapshot: &WorkingCopySnapshot,
258256
event_tx_id: EventTransactionId,
259-
message: Option<&str>,
257+
messages: Vec<String>,
260258
) -> EyreExitOr<()> {
261259
let old_tree = snapshot.commit_stage0.get_tree()?;
262260
let new_tree = snapshot.commit_unstaged.get_tree()?;
@@ -275,7 +273,7 @@ fn record_interactive(
275273
is_read_only: false,
276274
commits: vec![
277275
Commit {
278-
message: Some(message.map(|s| s.to_owned()).unwrap_or_default()),
276+
message: Some(messages.iter().join("\n\n")),
279277
},
280278
Commit { message: None },
281279
],

git-branchless-record/tests/test_record.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,24 @@ fn test_record_unstaged_changes() -> eyre::Result<()> {
1313
git.commit_file("test1", 1)?;
1414
git.write_file_txt("test1", "contents1\n")?;
1515
{
16-
let (stdout, _stderr) = git.branchless("record", &["-m", "foo"])?;
16+
let (stdout, _stderr) = git.branchless("record", &["-m", "foo", "-m", "bar"])?;
1717
insta::assert_snapshot!(stdout, @r###"
18-
[master 914812a] foo
18+
[master 872eae1] foo
1919
1 file changed, 1 insertion(+), 1 deletion(-)
2020
"###);
2121
}
2222

2323
{
2424
let (stdout, _stderr) = git.run(&["show"])?;
2525
insta::assert_snapshot!(stdout, @r###"
26-
commit 914812ae3220add483f11d851dc59f0b5dbdeaa0
26+
commit 872eae10daf1e94d0c346540f6d655027c60e7ae
2727
Author: Testy McTestface <test@example.com>
2828
Date: Thu Oct 29 12:34:56 2020 +0000
2929
3030
foo
3131
32+
bar
33+
3234
diff --git a/test1.txt b/test1.txt
3335
index 7432a8f..a024003 100644
3436
--- a/test1.txt

0 commit comments

Comments
 (0)