refactor(git): generic refactor
Started thinking about a new problem relating to how to deal with a series of operations, as quick has been doing so far. Now that we are trying to react to errors, it would be cool if we could stop early, but this require maintaining a list of things that have failed to avoid running them, and so we need to perform that logic inside of the function (at least it's the more reasonable approach imo) One way I can sketch rn might be to copy the hashmap structure of repos as a reference, and then delete the references from our cloned map as they fail. This is not ideal in any specific way, but it's a good first approximation. Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
parent
e11efb3229
commit
6d83d278e1
2 changed files with 51 additions and 32 deletions
41
src/git.rs
41
src/git.rs
|
@ -236,6 +236,9 @@ impl Config {
|
||||||
/// Runs associated function on all repos in config
|
/// Runs associated function on all repos in config
|
||||||
///
|
///
|
||||||
/// TODO: need to be made over a generic repo type
|
/// TODO: need to be made over a generic repo type
|
||||||
|
///
|
||||||
|
/// NOTE: currently unused
|
||||||
|
///
|
||||||
fn on_all<F>(&self, f: F)
|
fn on_all<F>(&self, f: F)
|
||||||
where
|
where
|
||||||
F: Fn(&GitRepo),
|
F: Fn(&GitRepo),
|
||||||
|
@ -262,6 +265,29 @@ impl Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// Runs associated function on all repos in config
|
||||||
|
///
|
||||||
|
/// TODO: need to be made over a generic repo type
|
||||||
|
///
|
||||||
|
/// NOTE: currently unused
|
||||||
|
///
|
||||||
|
/// # Current Problem
|
||||||
|
///
|
||||||
|
/// The goal of this function is that it should run some function on all
|
||||||
|
/// repos but stop executing further functions on any repo that fails,
|
||||||
|
/// without blocking the repos that don't have an issue.
|
||||||
|
///
|
||||||
|
/// This is actually somewhat hairy to do, at least at 6:16 am :S
|
||||||
|
fn series_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");
|
||||||
|
@ -291,17 +317,10 @@ impl Config {
|
||||||
/// 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");
|
||||||
self.on_all(|repo| {
|
self.on_all_spinner("pull", |repo| repo.pull());
|
||||||
let mut sp = Spinner::new(Spinners::Dots10, format!("{}: pull", repo.name).into());
|
self.on_all_spinner("add", |repo| repo.add_all());
|
||||||
repo.pull();
|
self.on_all_spinner("commit", |repo| repo.commit_with_msg(msg));
|
||||||
sp = Spinner::new(Spinners::Dots10, format!("{}: add_all", repo.name).into());
|
self.on_all_spinner("push", |repo| repo.push());
|
||||||
repo.add_all();
|
|
||||||
sp = Spinner::new(Spinners::Dots10, format!("{}: commit", repo.name).into());
|
|
||||||
repo.commit_with_msg(msg);
|
|
||||||
sp = Spinner::new(Spinners::Dots10, format!("{}: push", repo.name).into());
|
|
||||||
repo.push();
|
|
||||||
sp.stop_and_persist("✔", format!("{}: quick", repo.name).into());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* LINK RELATED */
|
/* LINK RELATED */
|
||||||
|
|
|
@ -1,24 +1,14 @@
|
||||||
categories:
|
categories:
|
||||||
config:
|
|
||||||
flags: []
|
|
||||||
repos:
|
|
||||||
qmk_firmware:
|
|
||||||
name: qmk_firmware
|
|
||||||
path: /home/ces/org/src/git/
|
|
||||||
url: git@github.com:cafkafk/qmk_firmware.git
|
|
||||||
flags:
|
|
||||||
- Clone
|
|
||||||
- Push
|
|
||||||
starship:
|
|
||||||
name: starship
|
|
||||||
path: /home/ces/org/src/git/
|
|
||||||
url: https://github.com/starship/starship.git
|
|
||||||
flags:
|
|
||||||
- Clone
|
|
||||||
- Push
|
|
||||||
utils:
|
utils:
|
||||||
flags: []
|
flags: []
|
||||||
repos:
|
repos:
|
||||||
|
gg:
|
||||||
|
name: gg
|
||||||
|
path: /home/ces/.dots/
|
||||||
|
url: git@github.com:cafkafk/gg.git
|
||||||
|
flags:
|
||||||
|
- Clone
|
||||||
|
- Push
|
||||||
li:
|
li:
|
||||||
name: li
|
name: li
|
||||||
path: /home/ces/org/src/git/
|
path: /home/ces/org/src/git/
|
||||||
|
@ -26,10 +16,20 @@ categories:
|
||||||
flags:
|
flags:
|
||||||
- Clone
|
- Clone
|
||||||
- Push
|
- Push
|
||||||
gg:
|
config:
|
||||||
name: gg
|
flags: []
|
||||||
path: /home/ces/.dots/
|
repos:
|
||||||
url: git@github.com:cafkafk/gg.git
|
starship:
|
||||||
|
name: starship
|
||||||
|
path: /home/ces/org/src/git/
|
||||||
|
url: https://github.com/starship/starship.git
|
||||||
|
flags:
|
||||||
|
- Clone
|
||||||
|
- Push
|
||||||
|
qmk_firmware:
|
||||||
|
name: qmk_firmware
|
||||||
|
path: /home/ces/org/src/git/
|
||||||
|
url: git@github.com:cafkafk/qmk_firmware.git
|
||||||
flags:
|
flags:
|
||||||
- Clone
|
- Clone
|
||||||
- Push
|
- Push
|
||||||
|
|
Loading…
Reference in a new issue