test fetch

This commit is contained in:
Stephan Dilly 2020-09-07 09:25:45 +02:00
parent 0bf9269327
commit 26565e9021
3 changed files with 40 additions and 8 deletions

View file

@ -47,7 +47,7 @@ pub fn get_remotes(repo_path: &str) -> Result<Vec<String>> {
///
pub fn fetch_origin(repo_path: &str, branch: &str) -> Result<usize> {
scope_time!("remote_fetch_master");
scope_time!("fetch_origin");
let repo = utils::repo(repo_path)?;
let mut remote = repo.find_remote("origin")?;
@ -96,12 +96,16 @@ fn remote_callbacks<'a>(
})
});
// log::debug!(
// "progress: {}/{} ({} B)",
// progress,
// total,
// bytes,
// );
log::debug!("progress: {}/{} ({} B)", current, total, bytes,);
});
callbacks.transfer_progress(|p| {
log::debug!(
"transfer progress: {} B / {} / {} ",
p.received_bytes(),
p.received_objects(),
p.total_objects()
);
true
});
callbacks.pack_progress(move |stage, current, total| {
sender.clone().map(|sender| {
@ -112,7 +116,7 @@ fn remote_callbacks<'a>(
})
});
// log::debug!("packing: {:?} - {}/{}", stage, current, total);
log::debug!("packing: {:?} - {}/{}", stage, current, total);
});
callbacks.credentials(|url, username_from_url, allowed_types| {
log::debug!(

View file

@ -61,6 +61,7 @@ pub struct KeyConfig {
pub copy: KeyEvent,
pub create_branch: KeyEvent,
pub push: KeyEvent,
pub fetch: KeyEvent,
}
#[rustfmt::skip]
@ -111,6 +112,7 @@ impl Default for KeyConfig {
copy: KeyEvent { code: KeyCode::Char('y'), modifiers: KeyModifiers::empty()},
create_branch: KeyEvent { code: KeyCode::Char('b'), modifiers: KeyModifiers::empty()},
push: KeyEvent { code: KeyCode::Char('p'), modifiers: KeyModifiers::empty()},
fetch: KeyEvent { code: KeyCode::Char('f'), modifiers: KeyModifiers::empty()},
}
}
}

View file

@ -333,6 +333,29 @@ impl Status {
.push_back(InternalEvent::Push(branch));
}
}
fn fetch(&self) {
if let Some(branch) = self.index_wd.branch_name() {
match sync::fetch_origin(CWD, branch.as_str()) {
Err(e) => {
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"fetch error:\n{}",
e
)),
);
}
Ok(bytes) => {
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"fetched:\n{} B",
bytes
)),
);
}
}
}
}
}
impl Component for Status {
@ -469,6 +492,9 @@ impl Component for Status {
} else if k == self.key_config.push {
self.push();
Ok(true)
} else if k == self.key_config.fetch {
self.fetch();
Ok(true)
} else {
Ok(false)
};