Skip to content

Commit 0a8a8b2

Browse files
krlvischacon
authored andcommitted
BUTCLI: adds the ability to remove marks
1 parent c7fb81d commit 0a8a8b2

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

crates/but/src/args.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,13 @@ For examples see `but rub --help`."
109109
/// The target entity to combine with the source
110110
target: String,
111111
},
112-
/// Creates a rule for auto-assigning or auto-comitting
112+
/// Creates or removes a rule for auto-assigning or auto-comitting
113113
Mark {
114114
/// The target entity that will be marked
115115
target: String,
116+
/// Deletes a mark
117+
#[clap(long, short = 'd')]
118+
delete: bool,
116119
},
117120
/// Starts up the MCP server.
118121
Mcp {

crates/but/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ async fn main() -> Result<()> {
169169
metrics_if_configured(app_settings, CommandName::Rub, props(start, &result)).ok();
170170
Ok(())
171171
}
172-
Subcommands::Mark { target } => {
173-
let result = mark::handle(&args.current_dir, args.json, target)
172+
Subcommands::Mark { target, delete } => {
173+
let result = mark::handle(&args.current_dir, args.json, target, *delete)
174174
.context("Can't mark this. Taaaa-na-na-na. Can't mark this.");
175175
if let Err(e) = &result {
176176
eprintln!("{} {}", e, e.root_cause());

crates/but/src/mark/mod.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ use but_rules::Operation;
66
use but_settings::AppSettings;
77
use gitbutler_command_context::CommandContext;
88
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<()> {
1015
let project = Project::from_path(repo_path).expect("Failed to create project from path");
1116
let ctx = &mut CommandContext::open(&project, AppSettings::load_from_default_path_creating()?)?;
1217
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:
1823
));
1924
}
2025
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),
2328
_ => bail!("Nope"),
2429
}
2530
}
2631

27-
fn mark_commit(_oid: gix::ObjectId) -> anyhow::Result<()> {
32+
fn mark_commit(_oid: gix::ObjectId, _delete: bool) -> anyhow::Result<()> {
2833
bail!("Not implemented yet");
2934
}
3035

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");
3449
let action = but_rules::Action::Explicit(Operation::Assign {
3550
target: but_rules::StackTarget::StackId(stack_id.to_string()),
3651
});

0 commit comments

Comments
 (0)