@@ -6,7 +6,12 @@ use but_rules::Operation;
6
6
use but_settings:: AppSettings ;
7
7
use gitbutler_command_context:: CommandContext ;
8
8
use gitbutler_project:: Project ;
9
- pub ( crate ) fn handle ( repo_path : & Path , _json : bool , target_str : & str ) -> anyhow:: Result < ( ) > {
9
+ pub ( crate ) fn handle (
10
+ repo_path : & Path ,
11
+ _json : bool ,
12
+ target_str : & str ,
13
+ delete : bool ,
14
+ ) -> anyhow:: Result < ( ) > {
10
15
let project = Project :: from_path ( repo_path) . expect ( "Failed to create project from path" ) ;
11
16
let ctx = & mut CommandContext :: open ( & project, AppSettings :: load_from_default_path_creating ( ) ?) ?;
12
17
let target_result = crate :: id:: CliId :: from_str ( ctx, target_str) ?;
@@ -18,19 +23,29 @@ pub(crate) fn handle(repo_path: &Path, _json: bool, target_str: &str) -> anyhow:
18
23
) ) ;
19
24
}
20
25
match target_result[ 0 ] . clone ( ) {
21
- crate :: id:: CliId :: Branch { name } => mark_branch ( ctx, name) ,
22
- crate :: id:: CliId :: Commit { oid } => mark_commit ( oid) ,
26
+ crate :: id:: CliId :: Branch { name } => mark_branch ( ctx, name, delete ) ,
27
+ crate :: id:: CliId :: Commit { oid } => mark_commit ( oid, delete ) ,
23
28
_ => bail ! ( "Nope" ) ,
24
29
}
25
30
}
26
31
27
- fn mark_commit ( _oid : gix:: ObjectId ) -> anyhow:: Result < ( ) > {
32
+ fn mark_commit ( _oid : gix:: ObjectId , _delete : bool ) -> anyhow:: Result < ( ) > {
28
33
bail ! ( "Not implemented yet" ) ;
29
34
}
30
35
31
- fn mark_branch ( ctx : & mut CommandContext , branch_name : String ) -> anyhow:: Result < ( ) > {
32
- let stack_id =
33
- branch_name_to_stack_id ( ctx, Some ( & branch_name) ) ?. expect ( "Cant find stack for this branch" ) ;
36
+ fn mark_branch ( ctx : & mut CommandContext , branch_name : String , delete : bool ) -> anyhow:: Result < ( ) > {
37
+ let stack_id = branch_name_to_stack_id ( ctx, Some ( & branch_name) ) ?;
38
+ if delete {
39
+ let rules = but_rules:: list_rules ( ctx) ?;
40
+ for rule in rules {
41
+ if rule. target_stack_id ( ) == stack_id. map ( |s| s. to_string ( ) ) {
42
+ but_rules:: delete_rule ( ctx, & rule. id ( ) ) ?;
43
+ }
44
+ }
45
+ println ! ( "Mark was removed" ) ;
46
+ return Ok ( ( ) ) ;
47
+ }
48
+ let stack_id = stack_id. expect ( "Cant find stack for this branch" ) ;
34
49
let action = but_rules:: Action :: Explicit ( Operation :: Assign {
35
50
target : but_rules:: StackTarget :: StackId ( stack_id. to_string ( ) ) ,
36
51
} ) ;
0 commit comments