Skip to content

Commit 7fc7b0c

Browse files
authored
Merge pull request #10490 from gitbutlerapp/kv-branch-57
Implement but unmark
2 parents 55c5d3b + 763dd8b commit 7fc7b0c

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

crates/but/src/args.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ For examples see `but rub --help`."
7676
#[clap(long, short = 'd')]
7777
delete: bool,
7878
},
79+
/// Removes all marks from the workspace
80+
Unmark,
7981
/// Commit changes to a stack.
8082
Commit {
8183
/// Commit message

crates/but/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ async fn main() -> Result<()> {
165165
metrics_if_configured(app_settings, CommandName::Rub, props(start, &result)).ok();
166166
Ok(())
167167
}
168+
Subcommands::Unmark => {
169+
let result = mark::unmark(&args.current_dir, args.json)
170+
.context("Can't unmark this. Taaaa-na-na-na. Can't unmark this.");
171+
if let Err(e) = &result {
172+
eprintln!("{} {}", e, e.root_cause());
173+
}
174+
metrics_if_configured(app_settings, CommandName::Rub, props(start, &result)).ok();
175+
Ok(())
176+
}
168177
Subcommands::Commit {
169178
message,
170179
branch,

crates/but/src/mark/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,27 @@ pub(crate) fn commit_marked(ctx: &mut CommandContext, commit_id: String) -> anyh
114114
.any(|r| r.target_commit_id() == Some(change_id.clone()));
115115
Ok(rules)
116116
}
117+
118+
pub(crate) fn unmark(repo_path: &Path, _json: bool) -> anyhow::Result<()> {
119+
let project = Project::find_by_path(repo_path).expect("Failed to create project from path");
120+
let ctx = &mut CommandContext::open(&project, AppSettings::load_from_default_path_creating()?)?;
121+
122+
let rules = but_rules::list_rules(ctx)?;
123+
let rule_count = rules.len();
124+
125+
if rule_count == 0 {
126+
println!("No marks to remove");
127+
return Ok(());
128+
}
129+
130+
for rule in rules {
131+
but_rules::delete_rule(ctx, &rule.id())?;
132+
}
133+
134+
println!(
135+
"Removed {} mark{}",
136+
rule_count,
137+
if rule_count == 1 { "" } else { "s" }
138+
);
139+
Ok(())
140+
}

0 commit comments

Comments
 (0)