From 26565e902111a16c216e0fd0233e62ea64905efc Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Mon, 7 Sep 2020 09:25:45 +0200 Subject: [PATCH] test fetch --- asyncgit/src/sync/remotes.rs | 20 ++++++++++++-------- src/keys.rs | 2 ++ src/tabs/status.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/asyncgit/src/sync/remotes.rs b/asyncgit/src/sync/remotes.rs index a572ced6..078f846a 100644 --- a/asyncgit/src/sync/remotes.rs +++ b/asyncgit/src/sync/remotes.rs @@ -47,7 +47,7 @@ pub fn get_remotes(repo_path: &str) -> Result> { /// pub fn fetch_origin(repo_path: &str, branch: &str) -> Result { - 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!( diff --git a/src/keys.rs b/src/keys.rs index 24d0ea1e..6083e408 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -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()}, } } } diff --git a/src/tabs/status.rs b/src/tabs/status.rs index 1ba040ab..ba54c6db 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -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) };