Skip to content

Commit 06ff772

Browse files
committed
Rule creation or update now triggers evaluation of all rules
1 parent a19437b commit 06ff772

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/but-rules/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ serde_regex = "1.1.0"
1919
serde_json = "1.0.138"
2020
gitbutler-command-context.workspace = true
2121
but-db.workspace = true
22+
but-core.workspace = true
2223
but-hunk-assignment.workspace = true
2324
but-graph.workspace = true
2425
but-workspace.workspace = true

crates/but-rules/src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use but_hunk_dependency::ui::hunk_dependencies_for_workspace_changes_by_worktree_dir;
12
use gitbutler_command_context::CommandContext;
23
use serde::{Deserialize, Serialize};
34

@@ -156,6 +157,7 @@ pub fn create_rule(
156157
.workspace_rules()
157158
.insert(rule.clone().try_into()?)
158159
.map_err(|e| anyhow::anyhow!("Failed to insert workspace rule: {}", e))?;
160+
process_rules(ctx).ok(); // Reevaluate rules after creating
159161
Ok(rule)
160162
}
161163

@@ -213,6 +215,7 @@ pub fn update_rule(
213215
.workspace_rules()
214216
.update(&req.id, rule.clone().try_into()?)
215217
.map_err(|e| anyhow::anyhow!("Failed to update workspace rule: {}", e))?;
218+
process_rules(ctx).ok(); // Reevaluate rules after updating
216219
Ok(rule)
217220
}
218221

@@ -227,3 +230,25 @@ pub fn list_rules(ctx: &mut CommandContext) -> anyhow::Result<Vec<WorkspaceRule>
227230
.collect::<Result<Vec<WorkspaceRule>, _>>()?;
228231
Ok(rules)
229232
}
233+
234+
fn process_rules(ctx: &mut CommandContext) -> anyhow::Result<()> {
235+
let wt_changes = but_core::diff::worktree_changes(&ctx.gix_repo()?)?;
236+
237+
let dependencies = hunk_dependencies_for_workspace_changes_by_worktree_dir(
238+
ctx,
239+
&ctx.project().path,
240+
&ctx.project().gb_dir(),
241+
Some(wt_changes.changes.clone()),
242+
)?;
243+
244+
let (assignments, _) = but_hunk_assignment::assignments_with_fallback(
245+
ctx,
246+
false,
247+
Some(wt_changes.changes),
248+
Some(&dependencies),
249+
)
250+
.map_err(|e| anyhow::anyhow!("Failed to get assignments: {}", e))?;
251+
252+
handler::process_workspace_rules(ctx, &assignments, &Some(dependencies))?;
253+
Ok(())
254+
}

0 commit comments

Comments
 (0)