Skip to content

Commit 359d2cd

Browse files
committed
Add --only flag to commit to skip unassigned files
Add an -o/--only option to the commit command so only files assigned to the target stack are committed and unassigned files are excluded when requested. This was needed to provide finer control over commits (commit only assigned files) instead of always including unassigned files. Changes: - CLI: add --only (-o) boolean flag to commit args. - Commit logic: respect the only flag and skip adding unassigned files when true. - Main wiring: pass the only flag from CLI into commit handler.
1 parent 270457f commit 359d2cd

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

crates/but/src/args.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ pub enum Subcommands {
6464
/// Stack ID or name to commit to (if multiple stacks exist)
6565
#[clap(short = 's', long = "stack")]
6666
stack: Option<String>,
67+
/// Only commit assigned files, not unassigned files
68+
#[clap(short = 'o', long = "only")]
69+
only: bool,
6770
},
6871
/// Insert a blank commit before the specified commit, or at the top of a stack.
6972
New {

crates/but/src/commit/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub(crate) fn commit(
1919
_json: bool,
2020
message: Option<&str>,
2121
stack_hint: Option<&str>,
22+
only: bool,
2223
) -> anyhow::Result<()> {
2324
let project = Project::from_path(repo_path)?;
2425
let mut ctx = CommandContext::open(&project, AppSettings::load_from_default_path_creating()?)?;
@@ -78,10 +79,12 @@ pub(crate) fn commit(
7879
// Get files to commit: unassigned files + files assigned to target stack
7980
let mut files_to_commit = Vec::new();
8081

81-
// Add unassigned files
82-
let unassigned =
83-
crate::status::assignment::filter_by_stack_id(assignments_by_file.values(), &None);
84-
files_to_commit.extend(unassigned);
82+
if !only {
83+
// Add unassigned files (unless --only flag is used)
84+
let unassigned =
85+
crate::status::assignment::filter_by_stack_id(assignments_by_file.values(), &None);
86+
files_to_commit.extend(unassigned);
87+
}
8588

8689
// Add files assigned to target stack
8790
let stack_assigned = crate::status::assignment::filter_by_stack_id(

crates/but/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,13 @@ async fn main() -> Result<()> {
130130
metrics_if_configured(app_settings, CommandName::Restore, props(start, &result)).ok();
131131
result
132132
}
133-
Subcommands::Commit { message, stack } => {
133+
Subcommands::Commit { message, stack, only } => {
134134
let result = commit::commit(
135135
&args.current_dir,
136136
args.json,
137137
message.as_deref(),
138138
stack.as_deref(),
139+
*only,
139140
);
140141
metrics_if_configured(app_settings, CommandName::Commit, props(start, &result)).ok();
141142
result

0 commit comments

Comments
 (0)