Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions git-branchless-opts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ pub struct RecordArgs {
/// After making the new commit, switch back to the previous commit.
#[clap(action, short = 's', long = "stash", conflicts_with_all(&["create", "detach"]))]
pub stash: bool,

/// Allow creating an empty commit.
#[clap(action, long = "allow-empty")]
pub allow_empty: bool,
}

/// Display a nice graph of the commits you've recently worked on.
Expand Down
7 changes: 7 additions & 0 deletions git-branchless-record/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub fn command_main(ctx: CommandContext, args: RecordArgs) -> EyreExitOr<()> {
detach,
insert,
stash,
allow_empty,
} = args;
record(
&effects,
Expand All @@ -68,6 +69,7 @@ pub fn command_main(ctx: CommandContext, args: RecordArgs) -> EyreExitOr<()> {
detach,
insert,
stash,
allow_empty,
)
}

Expand All @@ -81,6 +83,7 @@ fn record(
detach: bool,
insert: bool,
stash: bool,
allow_empty: bool,
) -> EyreExitOr<()> {
let now = SystemTime::now();
let repo = Repo::from_dir(&git_run_info.working_directory)?;
Expand All @@ -96,6 +99,7 @@ fn record(

let working_copy_changes_type = snapshot.get_working_copy_changes_type()?;
match working_copy_changes_type {
WorkingCopyChangesType::None if allow_empty => {}
WorkingCopyChangesType::None => {
writeln!(
effects.get_output_stream(),
Expand Down Expand Up @@ -170,6 +174,9 @@ fn record(
if working_copy_changes_type == WorkingCopyChangesType::Unstaged {
args.push("--all");
}
if allow_empty {
args.push("--allow-empty");
}
args
};
try_exit_code!(git_run_info.run_direct_no_wrapping(Some(event_tx_id), &args)?);
Expand Down
30 changes: 30 additions & 0 deletions git-branchless-record/tests/test_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,36 @@ fn test_record_staged_changes_interactive() -> eyre::Result<()> {
Ok(())
}

#[test]
fn test_record_allow_empty() -> eyre::Result<()> {
let git = make_git()?;

if !git.supports_reference_transactions()? {
return Ok(());
}
git.init_repo()?;

{
let (stdout, _stderr) = git.branchless("record", &["-m", "foo", "--allow-empty"])?;
insta::assert_snapshot!(stdout, @r###"
[master 315b284] foo
"###);
}

{
let (stdout, _stderr) = git.run(&["show"])?;
insta::assert_snapshot!(stdout, @r###"
commit 315b28467eb85c7ba0c94fac192744c043648a30
Author: Testy McTestface <[email protected]>
Date: Thu Oct 29 12:34:56 2020 +0000

foo
"###);
}

Ok(())
}

#[test]
fn test_record_detach() -> eyre::Result<()> {
let git = make_git()?;
Expand Down
Loading