mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-06 03:22:59 +00:00
branch forget
: error message if no globs match
This commit is contained in:
parent
7fde64fe8f
commit
144a44914a
2 changed files with 45 additions and 11 deletions
|
@ -232,17 +232,36 @@ fn cmd_branch_forget(
|
||||||
args: &BranchForgetArgs,
|
args: &BranchForgetArgs,
|
||||||
) -> Result<(), CommandError> {
|
) -> Result<(), CommandError> {
|
||||||
fn find_globs(view: &View, globs: &[String]) -> Result<Vec<String>, CommandError> {
|
fn find_globs(view: &View, globs: &[String]) -> Result<Vec<String>, CommandError> {
|
||||||
let globs: Vec<glob::Pattern> = globs
|
let mut matching_branches: Vec<String> = vec![];
|
||||||
.iter()
|
let mut failed_globs = vec![];
|
||||||
.map(|glob| glob::Pattern::new(glob))
|
for glob_str in globs {
|
||||||
.try_collect()?;
|
let glob = glob::Pattern::new(glob_str)?;
|
||||||
let matching_branches = view
|
let names = view
|
||||||
.branches()
|
.branches()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(branch_name, _branch_target)| branch_name)
|
.map(|(branch_name, _branch_target)| branch_name)
|
||||||
.filter(|branch_name| globs.iter().any(|glob| glob.matches(branch_name)))
|
.filter(|branch_name| glob.matches(branch_name))
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect_vec();
|
||||||
|
if names.is_empty() {
|
||||||
|
failed_globs.push(glob);
|
||||||
|
}
|
||||||
|
matching_branches.extend(names.into_iter());
|
||||||
|
}
|
||||||
|
match &failed_globs[..] {
|
||||||
|
[] => { /* No problem */ }
|
||||||
|
[glob] => {
|
||||||
|
return Err(user_error(format!(
|
||||||
|
"The provided glob '{glob}' did not match any branches"
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
globs => {
|
||||||
|
return Err(user_error(format!(
|
||||||
|
"The provided globs '{}' did not match any branches",
|
||||||
|
globs.iter().join("', '")
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
};
|
||||||
Ok(matching_branches)
|
Ok(matching_branches)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,21 @@ fn test_branch_forget_glob() {
|
||||||
insta::assert_snapshot!(stderr, @r###"
|
insta::assert_snapshot!(stderr, @r###"
|
||||||
Error: Failed to compile glob: Pattern syntax error near position 4: invalid range pattern
|
Error: Failed to compile glob: Pattern syntax error near position 4: invalid range pattern
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
|
// We get an error if none of the globs match anything
|
||||||
|
let stderr = test_env.jj_cmd_failure(
|
||||||
|
&repo_path,
|
||||||
|
&[
|
||||||
|
"branch",
|
||||||
|
"forget",
|
||||||
|
"--glob=bar*",
|
||||||
|
"--glob=baz*",
|
||||||
|
"--glob=boom*",
|
||||||
|
],
|
||||||
|
);
|
||||||
|
insta::assert_snapshot!(stderr, @r###"
|
||||||
|
Error: The provided globs 'baz*', 'boom*' did not match any branches
|
||||||
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue