Skip to content

Commit c9ac69c

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 a221ff0 commit c9ac69c

File tree

2 files changed

+11
-1
lines changed
  • git-branchless-opts/src
  • git-branchless-record/src

2 files changed

+11
-1
lines changed

git-branchless-opts/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ pub struct RecordArgs {
334334
/// How should newly encountered, untracked files be handled?
335335
#[clap(value_parser, long = "untracked", conflicts_with_all(&["interactive"]))]
336336
pub untracked_file_strategy: Option<UntrackedFileStrategy>,
337+
338+
/// Allow creating an empty commit.
339+
#[clap(action, long = "allow-empty")]
340+
pub allow_empty: bool,
337341
}
338342

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

git-branchless-record/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub fn command_main(ctx: CommandContext, args: RecordArgs) -> EyreExitOr<()> {
6060
insert,
6161
stash,
6262
untracked_file_strategy,
63+
allow_empty,
6364
} = args;
6465
record(
6566
&effects,
@@ -71,6 +72,7 @@ pub fn command_main(ctx: CommandContext, args: RecordArgs) -> EyreExitOr<()> {
7172
insert,
7273
stash,
7374
untracked_file_strategy,
75+
allow_empty,
7476
)
7577
}
7678

@@ -85,6 +87,7 @@ fn record(
8587
insert: bool,
8688
stash: bool,
8789
untracked_file_strategy: Option<UntrackedFileStrategy>,
90+
allow_empty: bool,
8891
) -> EyreExitOr<()> {
8992
let now = SystemTime::now();
9093
let repo = Repo::from_dir(&git_run_info.working_directory)?;
@@ -113,7 +116,7 @@ fn record(
113116
)?)
114117
};
115118

116-
if files_to_add.is_empty() {
119+
if files_to_add.is_empty() && !allow_empty {
117120
writeln!(
118121
effects.get_output_stream(),
119122
"There are no changes to tracked files in the working copy to commit."
@@ -222,6 +225,9 @@ fn record(
222225
if working_copy_changes_type == WorkingCopyChangesType::Unstaged {
223226
args.push("--all");
224227
}
228+
if allow_empty {
229+
args.push("--allow-empty");
230+
}
225231
args
226232
};
227233
try_exit_code!(git_run_info.run_direct_no_wrapping(Some(event_tx_id), &args)?);

0 commit comments

Comments
 (0)