Skip to content

Commit a897fc4

Browse files
feat(record): add --allow-empty
Primarily for creating new, empty commits with automatic rebasing, for when you know you want to add something into a stack but you're not yet sure what.
1 parent 113cc19 commit a897fc4

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

git-branchless-opts/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ pub struct RecordArgs {
329329
/// After making the new commit, switch back to the previous commit.
330330
#[clap(action, short = 's', long = "stash", conflicts_with_all(&["create", "detach"]))]
331331
pub stash: bool,
332+
333+
/// Allow creating an empty commit.
334+
#[clap(action, long = "allow-empty")]
335+
pub allow_empty: bool,
332336
}
333337

334338
/// Display a nice graph of the commits you've recently worked on.

git-branchless-record/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub fn command_main(ctx: CommandContext, args: RecordArgs) -> EyreExitOr<()> {
5858
detach,
5959
insert,
6060
stash,
61+
allow_empty,
6162
} = args;
6263
record(
6364
&effects,
@@ -68,6 +69,7 @@ pub fn command_main(ctx: CommandContext, args: RecordArgs) -> EyreExitOr<()> {
6869
detach,
6970
insert,
7071
stash,
72+
allow_empty,
7173
)
7274
}
7375

@@ -81,6 +83,7 @@ fn record(
8183
detach: bool,
8284
insert: bool,
8385
stash: bool,
86+
allow_empty: bool,
8487
) -> EyreExitOr<()> {
8588
let now = SystemTime::now();
8689
let repo = Repo::from_dir(&git_run_info.working_directory)?;
@@ -96,6 +99,7 @@ fn record(
9699

97100
let working_copy_changes_type = snapshot.get_working_copy_changes_type()?;
98101
match working_copy_changes_type {
102+
WorkingCopyChangesType::None if allow_empty => {}
99103
WorkingCopyChangesType::None => {
100104
writeln!(
101105
effects.get_output_stream(),
@@ -170,6 +174,9 @@ fn record(
170174
if working_copy_changes_type == WorkingCopyChangesType::Unstaged {
171175
args.push("--all");
172176
}
177+
if allow_empty {
178+
args.push("--allow-empty");
179+
}
173180
args
174181
};
175182
try_exit_code!(git_run_info.run_direct_no_wrapping(Some(event_tx_id), &args)?);

git-branchless-record/tests/test_record.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,36 @@ fn test_record_staged_changes_interactive() -> eyre::Result<()> {
222222
Ok(())
223223
}
224224

225+
#[test]
226+
fn test_record_allow_empty() -> eyre::Result<()> {
227+
let git = make_git()?;
228+
229+
if !git.supports_reference_transactions()? {
230+
return Ok(());
231+
}
232+
git.init_repo()?;
233+
234+
{
235+
let (stdout, _stderr) = git.branchless("record", &["-m", "foo", "--allow-empty"])?;
236+
insta::assert_snapshot!(stdout, @r###"
237+
[master 315b284] foo
238+
"###);
239+
}
240+
241+
{
242+
let (stdout, _stderr) = git.run(&["show"])?;
243+
insta::assert_snapshot!(stdout, @r###"
244+
commit 315b28467eb85c7ba0c94fac192744c043648a30
245+
Author: Testy McTestface <[email protected]>
246+
Date: Thu Oct 29 12:34:56 2020 +0000
247+
248+
foo
249+
"###);
250+
}
251+
252+
Ok(())
253+
}
254+
225255
#[test]
226256
fn test_record_detach() -> eyre::Result<()> {
227257
let git = make_git()?;

0 commit comments

Comments
 (0)