refactor(git): created on_all for config struct
This commit introduces on_all() on the config struct. This unifies behaviour for iterating over all repos in the config. I'm introducing this to make testing various architectural choices a breeze. NOTE: Ideally, GitRepo should also be made generic, allowing other types of repos at some point. Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
parent
d43abc0624
commit
6cebe88131
1 changed files with 29 additions and 28 deletions
41
src/git.rs
41
src/git.rs
|
@ -210,6 +210,17 @@ impl Config {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
/// Runs associated function on all repos in config
|
||||||
|
fn on_all<F>(&self, f: F)
|
||||||
|
where
|
||||||
|
F: Fn(&GitRepo),
|
||||||
|
{
|
||||||
|
for category in self.categories.iter() {
|
||||||
|
for repo in category.repos.iter() {
|
||||||
|
f(repo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/// Tries to pull all repositories, skips if fail.
|
/// Tries to pull all repositories, skips if fail.
|
||||||
pub fn pull_all(&self) {
|
pub fn pull_all(&self) {
|
||||||
debug!("exectuting pull_all");
|
debug!("exectuting pull_all");
|
||||||
|
@ -222,51 +233,41 @@ impl Config {
|
||||||
/// Tries to clone all repositories, skips if fail.
|
/// Tries to clone all repositories, skips if fail.
|
||||||
pub fn clone_all(&self) {
|
pub fn clone_all(&self) {
|
||||||
debug!("exectuting clone_all");
|
debug!("exectuting clone_all");
|
||||||
for category in self.categories.iter() {
|
self.on_all(|repo| {
|
||||||
for repo in category.repos.iter() {
|
|
||||||
repo.clone();
|
repo.clone();
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// Tries to add all work in all repositories, skips if fail.
|
/// Tries to add all work in all repositories, skips if fail.
|
||||||
pub fn add_all(&self) {
|
pub fn add_all(&self) {
|
||||||
debug!("exectuting clone_all");
|
debug!("exectuting clone_all");
|
||||||
for category in self.categories.iter() {
|
self.on_all(|repo| {
|
||||||
for repo in category.repos.iter() {
|
|
||||||
repo.add_all();
|
repo.add_all();
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// Tries to commit all repositories one at a time, skips if fail.
|
/// Tries to commit all repositories one at a time, skips if fail.
|
||||||
pub fn commit_all(&self) {
|
pub fn commit_all(&self) {
|
||||||
debug!("exectuting clone_all");
|
debug!("exectuting clone_all");
|
||||||
for category in self.categories.iter() {
|
self.on_all(|repo| {
|
||||||
for repo in category.repos.iter() {
|
|
||||||
repo.commit();
|
repo.commit();
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// Tries to commit all repositories with msg, skips if fail.
|
/// Tries to commit all repositories with msg, skips if fail.
|
||||||
pub fn commit_all_msg(&self, msg: &String) {
|
pub fn commit_all_msg(&self, msg: &String) {
|
||||||
debug!("exectuting clone_all");
|
debug!("exectuting clone_all");
|
||||||
for category in self.categories.iter() {
|
self.on_all(|repo| {
|
||||||
for repo in category.repos.iter() {
|
|
||||||
repo.commit_with_msg(msg);
|
repo.commit_with_msg(msg);
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// Tries to pull, add all, commit with msg "quick commit", and push all
|
/// Tries to pull, add all, commit with msg "quick commit", and push all
|
||||||
/// repositories, skips if fail.
|
/// repositories, skips if fail.
|
||||||
pub fn quick(&self, msg: &String) {
|
pub fn quick(&self, msg: &String) {
|
||||||
debug!("exectuting quick");
|
debug!("exectuting quick");
|
||||||
for category in self.categories.iter() {
|
self.on_all(|repo| {
|
||||||
for repo in category.repos.iter() {
|
|
||||||
repo.pull();
|
repo.pull();
|
||||||
repo.add_all();
|
repo.add_all();
|
||||||
repo.commit_with_msg(msg);
|
repo.commit_with_msg(msg);
|
||||||
repo.push();
|
repo.push();
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* LINK RELATED */
|
/* LINK RELATED */
|
||||||
|
|
Loading…
Reference in a new issue