Hi I wrote code which deletes branches on submodules of a git-repository. My code is functional but uses 13 level of indention to delete the branches. Can I write this simpler, nicer or better?
pub fn forget(y: &clap::ArgMatches) {
let branchname = y.value_of("branchname").unwrap();
match Repository::discover(".") {
Ok(repo) => {
/* remove branch on the current repository */
match repo.branches(Some(BranchType::Local)) {
Ok(branches) => {
for b in branches {
match b {
Ok((mut b, _)) => {
if b.name().unwrap().unwrap() == branchname {
println!("delete {} in current folder", branchname);
b.delete();
}
},
Err(e) => { println!("fila ({})", e); return; },
}
}
},
Err(e) => { println!("fila ({})", e); return; },
}
/* remove branch on all submodules */
match repo.submodules() {
Ok(submodules) => {
for sm in submodules.iter() {
match sm.open() {
Ok(reposub) => {
match reposub.branches(Some(BranchType::Local)) {
Ok(branches) => {
for b in branches {
match b {
Ok((mut b, _)) => {
if b.name().unwrap().unwrap() == branchname {
println!("delete {} in {}", branchname, sm.name().unwrap());
b.delete();
}
},
Err(e) => { println!("fila ({})", e); return; },
}
}
},
Err(e) => { println!("fila ({})", e); return; },
}
},
Err(e) => { println!("fila ({})", e); return; },
}
}
},
Err(e) => { println!("fila ({})", e); return; },
}
},
Err(e) => { println!("fila ({})", e); return; },
}
}