step fifty eight: download remote ref values

This commit is contained in:
Gonçalo Valério 2020-12-02 23:38:22 +00:00
parent 1b1af9fac1
commit 70a660e2f5
1 changed files with 17 additions and 3 deletions

View File

@ -3,10 +3,24 @@ use std::collections::HashMap;
#[path = "data.rs"]
mod data;
static REMOTE_REFS_BASE: &'static str = "refs/heads/";
static LOCAL_REFS_BASE: &'static str = "refs/remote/";
pub fn fetch(path: String) {
println!("Will fetch the following refs:");
for (refname, _) in get_remote_refs(path, "refs/heads").iter() {
println!("- {}", refname);
// Get refs from server
let refs = get_remote_refs(path, REMOTE_REFS_BASE);
// Update local refs to match server
for (remote_name, value) in refs.iter() {
let refname = remote_name.trim_start_matches(REMOTE_REFS_BASE);
data::update_ref(
format!("{}/{}", LOCAL_REFS_BASE, refname),
data::RefValue {
symbolic: false,
value: value.clone(),
},
true,
)
}
}