diff options
| author | qvkap <qvkapp@gmail.com> | 2026-10-05 19:54:51 +0300 |
|---|---|---|
| committer | qvkap <qvkapp@gmail.com> | 2026-10-05 19:54:51 +0300 |
| commit | 78828df65dfc90d30e82490b290db04ebf2c6f30 (patch) | |
| tree | df81438ed7323167d177a7074dafcba59726b06c /src/sync.rs | |
| parent | f267c259163e121ff376bd764b10767a7939ef79 (diff) | |
| download | ror-78828df65dfc90d30e82490b290db04ebf2c6f30.tar.gz ror-78828df65dfc90d30e82490b290db04ebf2c6f30.zip | |
fix: sync uses fetch+reset instead of pull, group supports direct .yaml path from cwd
Diffstat (limited to 'src/sync.rs')
| -rw-r--r-- | src/sync.rs | 59 |
1 files changed, 21 insertions, 38 deletions
diff --git a/src/sync.rs b/src/sync.rs index 2d1b6b7..78687cd 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -59,24 +59,18 @@ pub fn run_sync(cfg: &Config) { eprintln!("{} {}: {}", "[ror]".red().bold(), name, e); continue; } - if let Some(ref mirror) = repo.mirror { - if let Err(e) = enforce_repo_https(mirror) { - eprintln!("{} {}: {}", "[ror]".red().bold(), name, e); - continue; - } - } println!("{} Syncing repository '{}'...", "[ror]".blue().bold(), name); let repo_path = Path::new(REPOS_DIR).join(name); if repo_path.exists() { println!("{} Updating {}...", ">>>".green(), name); - if let Err(e) = pull_repo(&repo_path, repo.mirror.as_deref()) { + if let Err(e) = pull_repo(&repo_path) { eprintln!("{} {}", "[ror]".red(), e); } else { println!("{} Repository updated.", ">>>".green()); } } else { println!("{} Cloning {}...", ">>>".green(), name); - if let Err(e) = clone_repo(name, &repo.url, repo.mirror.as_deref()) { + if let Err(e) = clone_repo(name, &repo.url) { eprintln!("{} {}", "[ror]".red(), e); } else { println!("{} Repository cloned.", ">>>".green()); @@ -85,7 +79,7 @@ pub fn run_sync(cfg: &Config) { } } -fn clone_repo(name: &str, primary: &str, mirror: Option<&str>) -> Result<(), String> { +fn clone_repo(name: &str, primary: &str) -> Result<(), String> { let path = Path::new(REPOS_DIR).join(name); if let Some(parent) = path.parent() { std::fs::create_dir_all(parent).map_err(|e| format!("Failed to create repos dir: {}", e))?; @@ -100,44 +94,33 @@ fn clone_repo(name: &str, primary: &str, mirror: Option<&str>) -> Result<(), Str return Ok(()); } - if let Some(mirror_url) = mirror { - eprintln!("{} Primary clone failed, trying mirror...", "[ror]".yellow()); - let mirror_status = Command::new("git") - .args(["clone", mirror_url, path.to_str().unwrap()]) - .status() - .map_err(|e| format!("Failed to run git clone for mirror: {}", e))?; - - if mirror_status.success() { - return Ok(()); - } - } - Err(format!("Failed to clone repository '{}'", name)) } -fn pull_repo(repo_path: &Path, mirror: Option<&str>) -> Result<(), String> { +fn pull_repo(repo_path: &Path) -> Result<(), String> { let path_str = repo_path.to_str().ok_or("Invalid repo path")?; - let status = Command::new("git") - .args(["-C", path_str, "pull"]) + + let fetch = Command::new("git") + .args(["-C", path_str, "fetch", "origin"]) .status() - .map_err(|e| format!("Failed to run git pull: {}", e))?; + .map_err(|e| format!("Failed to run git fetch: {}", e))?; - if status.success() { - return Ok(()); + if !fetch.success() { + return Err(format!("git fetch failed for '{}'", path_str)); } - if let Some(mirror_url) = mirror { - eprintln!("{} Pull from primary failed, trying mirror...", "[ror]".yellow()); - let mirror_status = Command::new("git") - .args(["-C", path_str, "pull", mirror_url]) - .status() - .map_err(|e| format!("Failed to run git pull from mirror: {}", e))?; + let _ = Command::new("git") + .args(["-C", path_str, "clean", "-fd"]) + .status(); - if mirror_status.success() { - return Ok(()); - } + let reset = Command::new("git") + .args(["-C", path_str, "reset", "--hard", "FETCH_HEAD"]) + .status() + .map_err(|e| format!("Failed to run git reset: {}", e))?; + + if reset.success() { + return Ok(()); } - Err(format!("Failed to pull repository at '{}'", path_str)) + Err(format!("Failed to update repository at '{}'", path_str)) } - |