1
+ use but_hunk_dependency:: ui:: hunk_dependencies_for_workspace_changes_by_worktree_dir;
1
2
use gitbutler_command_context:: CommandContext ;
2
3
use serde:: { Deserialize , Serialize } ;
3
4
@@ -156,6 +157,7 @@ pub fn create_rule(
156
157
. workspace_rules ( )
157
158
. insert ( rule. clone ( ) . try_into ( ) ?)
158
159
. map_err ( |e| anyhow:: anyhow!( "Failed to insert workspace rule: {}" , e) ) ?;
160
+ process_rules ( ctx) . ok ( ) ; // Reevaluate rules after creating
159
161
Ok ( rule)
160
162
}
161
163
@@ -213,6 +215,7 @@ pub fn update_rule(
213
215
. workspace_rules ( )
214
216
. update ( & req. id , rule. clone ( ) . try_into ( ) ?)
215
217
. map_err ( |e| anyhow:: anyhow!( "Failed to update workspace rule: {}" , e) ) ?;
218
+ process_rules ( ctx) . ok ( ) ; // Reevaluate rules after updating
216
219
Ok ( rule)
217
220
}
218
221
@@ -227,3 +230,25 @@ pub fn list_rules(ctx: &mut CommandContext) -> anyhow::Result<Vec<WorkspaceRule>
227
230
. collect :: < Result < Vec < WorkspaceRule > , _ > > ( ) ?;
228
231
Ok ( rules)
229
232
}
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