From 17f4a7d9f92d77386a5f68d09e79beeb5c7f42c6 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Tue, 29 Sep 2020 20:48:29 +0100 Subject: [PATCH 01/26] Add support for force push --- asyncgit/src/push.rs | 3 +++ asyncgit/src/sync/remotes.rs | 10 +++++++++- src/app.rs | 4 ++-- src/components/push.rs | 19 +++++++++++++++++-- src/keys.rs | 2 ++ src/queue.rs | 2 +- src/strings.rs | 1 + src/tabs/status.rs | 9 ++++++--- 8 files changed, 41 insertions(+), 9 deletions(-) diff --git a/asyncgit/src/push.rs b/asyncgit/src/push.rs index 2533dcc2fe..49bfa5c48d 100644 --- a/asyncgit/src/push.rs +++ b/asyncgit/src/push.rs @@ -88,6 +88,8 @@ pub struct PushRequest { pub remote: String, /// pub branch: String, + /// + pub force: bool, } #[derive(Default, Clone, Debug)] @@ -161,6 +163,7 @@ impl AsyncPush { CWD, params.remote.as_str(), params.branch.as_str(), + params.force, progress_sender.clone(), ); diff --git a/asyncgit/src/sync/remotes.rs b/asyncgit/src/sync/remotes.rs index 278b3cccc9..a3512130c9 100644 --- a/asyncgit/src/sync/remotes.rs +++ b/asyncgit/src/sync/remotes.rs @@ -83,6 +83,7 @@ pub fn push( repo_path: &str, remote: &str, branch: &str, + force: bool, progress_sender: Sender, ) -> Result<()> { scope_time!("push_origin"); @@ -95,7 +96,14 @@ pub fn push( options.remote_callbacks(remote_callbacks(Some(progress_sender))); options.packbuilder_parallelism(0); - remote.push(&[branch], Some(&mut options))?; + if force { + remote.push( + &[String::from("+") + branch], + Some(&mut options), + )?; + } else { + remote.push(&[branch], Some(&mut options))?; + } Ok(()) } diff --git a/src/app.rs b/src/app.rs index 4136c26d54..228745d608 100644 --- a/src/app.rs +++ b/src/app.rs @@ -497,8 +497,8 @@ impl App { self.file_to_open = path; flags.insert(NeedsUpdate::COMMANDS) } - InternalEvent::Push(branch) => { - self.push_popup.push(branch)?; + InternalEvent::Push(branch, force) => { + self.push_popup.push(branch, force)?; flags.insert(NeedsUpdate::ALL) } }; diff --git a/src/components/push.rs b/src/components/push.rs index 6cc9d9ad8e..c55f78cb79 100644 --- a/src/components/push.rs +++ b/src/components/push.rs @@ -26,6 +26,7 @@ use tui::{ /// pub struct PushComponent { visible: bool, + force: bool, git_push: AsyncPush, progress: Option, pending: bool, @@ -44,6 +45,7 @@ impl PushComponent { ) -> Self { Self { queue: queue.clone(), + force: false, pending: false, visible: false, git_push: AsyncPush::new(sender), @@ -54,14 +56,23 @@ impl PushComponent { } /// - pub fn push(&mut self, branch: String) -> Result<()> { + pub fn push( + &mut self, + branch: String, + force: bool, + ) -> Result<()> { self.pending = true; self.progress = None; self.git_push.request(PushRequest { //TODO: find tracking branch name remote: String::from("origin"), branch, + force, })?; + + if force { + self.force = true; + } self.show()?; Ok(()) } @@ -146,7 +157,11 @@ impl DrawableComponent for PushComponent { .label(state.as_str()) .block( Block::default() - .title(strings::PUSH_POPUP_MSG) + .title(if self.force { + strings::FORCE_PUSH_POPUP_MSG + } else { + strings::PUSH_POPUP_MSG + }) .borders(Borders::ALL) .border_type(BorderType::Thick) .title_style(self.theme.title(true)) diff --git a/src/keys.rs b/src/keys.rs index 6083e408a2..5f7c3cd33a 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 force_push: KeyEvent, pub fetch: KeyEvent, } @@ -112,6 +113,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()}, + force_push: KeyEvent { code: KeyCode::Char('p'), modifiers: KeyModifiers::SHIFT}, fetch: KeyEvent { code: KeyCode::Char('f'), modifiers: KeyModifiers::empty()}, } } diff --git a/src/queue.rs b/src/queue.rs index 23af8f4073..ee0238595f 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -55,7 +55,7 @@ pub enum InternalEvent { /// OpenExternalEditor(Option), /// - Push(String), + Push(String, bool), } /// diff --git a/src/strings.rs b/src/strings.rs index bbedebe881..7a7a0f7f39 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -5,6 +5,7 @@ pub mod order { } pub static PUSH_POPUP_MSG: &str = "Push"; +pub static FORCE_PUSH_POPUP_MSG: &str = "Force Push"; pub static PUSH_POPUP_PROGRESS_NONE: &str = "preparing..."; pub static PUSH_POPUP_STATES_ADDING: &str = "adding objects (1/3)"; pub static PUSH_POPUP_STATES_DELTAS: &str = "deltas (2/3)"; diff --git a/src/tabs/status.rs b/src/tabs/status.rs index ba54c6db58..2f66ed3c5d 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -324,13 +324,13 @@ impl Status { } } - fn push(&self) { + fn push(&self, force: bool) { if let Some(branch) = self.index_wd.branch_name() { let branch = format!("refs/heads/{}", branch); self.queue .borrow_mut() - .push_back(InternalEvent::Push(branch)); + .push_back(InternalEvent::Push(branch, force)); } } @@ -490,7 +490,10 @@ impl Component for Status { .push_back(InternalEvent::CreateBranch); Ok(true) } else if k == self.key_config.push { - self.push(); + self.push(false); + Ok(true) + } else if k == self.key_config.force_push { + self.push(true); Ok(true) } else if k == self.key_config.fetch { self.fetch(); From eecc7d86aa0417c930a6f58f03a0f9a3849ed13c Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Tue, 29 Sep 2020 21:07:13 +0100 Subject: [PATCH 02/26] Add Force Push to cmdbar --- src/strings.rs | 12 ++++++++++++ src/tabs/status.rs | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/src/strings.rs b/src/strings.rs index 7a7a0f7f39..f6e2c7bd3a 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -610,4 +610,16 @@ pub mod commands { CMD_GROUP_GENERAL, ) } + pub fn status_force_push( + key_config: &SharedKeyConfig, + ) -> CommandText { + CommandText::new( + format!( + "Force Push [{}]", + get_hint(key_config.force_push), + ), + "force push to origin", + CMD_GROUP_GENERAL, + ) + } } diff --git a/src/tabs/status.rs b/src/tabs/status.rs index 2f66ed3c5d..2ebb39eb9a 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -407,6 +407,11 @@ impl Component for Status { self.index_wd.branch_name().is_some(), true, )); + out.push(CommandInfo::new( + strings::commands::status_force_push(&self.key_config), + self.index_wd.branch_name().is_some(), + true, + )); out.push( CommandInfo::new( From b0dfef97ba5473313d8186a0eee44789cc126233 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Sun, 4 Oct 2020 23:43:35 +0100 Subject: [PATCH 03/26] Remove unnessessary if --- src/components/push.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/push.rs b/src/components/push.rs index c55f78cb79..0710206ebb 100644 --- a/src/components/push.rs +++ b/src/components/push.rs @@ -69,10 +69,8 @@ impl PushComponent { branch, force, })?; + self.force = force; - if force { - self.force = true; - } self.show()?; Ok(()) } From 57455d3e10ea78d55fd89cff86087ec23e8e8057 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Sun, 4 Oct 2020 23:57:34 +0100 Subject: [PATCH 04/26] Change p to P --- src/keys.rs | 2 +- src/tabs/status.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/keys.rs b/src/keys.rs index 5f7c3cd33a..639db19c9f 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -113,7 +113,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()}, - force_push: KeyEvent { code: KeyCode::Char('p'), modifiers: KeyModifiers::SHIFT}, + force_push: KeyEvent { code: KeyCode::Char('P'), modifiers: KeyModifiers::SHIFT}, fetch: KeyEvent { code: KeyCode::Char('f'), modifiers: KeyModifiers::empty()}, } } diff --git a/src/tabs/status.rs b/src/tabs/status.rs index 2ebb39eb9a..cb22e3092e 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -494,12 +494,12 @@ impl Component for Status { .borrow_mut() .push_back(InternalEvent::CreateBranch); Ok(true) - } else if k == self.key_config.push { - self.push(false); - Ok(true) } else if k == self.key_config.force_push { self.push(true); Ok(true) + } else if k == self.key_config.push { + self.push(false); + Ok(true) } else if k == self.key_config.fetch { self.fetch(); Ok(true) From de4ea266861db81bf6bb92f6b8780585d06f4825 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Sun, 8 Nov 2020 09:44:21 +0000 Subject: [PATCH 05/26] use ' \u{200b}' for a ' ' so tui doesn't remove --- src/components/textinput.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/textinput.rs b/src/components/textinput.rs index 50c625751d..6c50f78356 100644 --- a/src/components/textinput.rs +++ b/src/components/textinput.rs @@ -142,7 +142,7 @@ impl TextInputComponent { .next_char_position() // if the cursor is at the end of the msg // a whitespace is used to underline - .map_or(" ".to_owned(), |pos| { + .map_or(" \u{200b}".to_owned(), |pos| { self.get_msg(self.cursor_position..pos) }); From cf9547c8c02540767c2faae88fd971e6671696dc Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Fri, 13 Nov 2020 00:06:27 +0000 Subject: [PATCH 06/26] Revert "use ' \u{200b}' for a ' ' so tui doesn't remove" This reverts commit de4ea266861db81bf6bb92f6b8780585d06f4825. --- src/components/textinput.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/textinput.rs b/src/components/textinput.rs index 6c50f78356..50c625751d 100644 --- a/src/components/textinput.rs +++ b/src/components/textinput.rs @@ -142,7 +142,7 @@ impl TextInputComponent { .next_char_position() // if the cursor is at the end of the msg // a whitespace is used to underline - .map_or(" \u{200b}".to_owned(), |pos| { + .map_or(" ".to_owned(), |pos| { self.get_msg(self.cursor_position..pos) }); From d3bcaaf655e9c988108fdd29e76738191c42ac61 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Fri, 13 Nov 2020 00:12:25 +0000 Subject: [PATCH 07/26] Fix vim test --- assets/vim_style_key_config.ron | 1 + 1 file changed, 1 insertion(+) diff --git a/assets/vim_style_key_config.ron b/assets/vim_style_key_config.ron index 6afc7ef269..c7eda0011c 100644 --- a/assets/vim_style_key_config.ron +++ b/assets/vim_style_key_config.ron @@ -69,5 +69,6 @@ select_branch: ( code: Char('b'), modifiers: ( bits: 0,),), delete_branch: ( code: Char('D'), modifiers: ( bits: 1,),), push: ( code: Char('p'), modifiers: ( bits: 0,),), + force_push: ( code: Char('p'), modifiers: ( bits: 2,),), fetch: ( code: Char('f'), modifiers: ( bits: 0,),), ) From 9759bfe041dc6c421f0601455144861c1c515d7a Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Fri, 13 Nov 2020 00:27:55 +0000 Subject: [PATCH 08/26] Add confirm popup before force pushing --- src/app.rs | 4 ++++ src/components/reset.rs | 9 +++++++++ src/queue.rs | 1 + src/strings.rs | 14 ++++++++++++++ src/tabs/status.rs | 16 ++++++++++++---- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/app.rs b/src/app.rs index d9fa1fb9e2..7ffc8beddc 100644 --- a/src/app.rs +++ b/src/app.rs @@ -494,6 +494,10 @@ impl App { self.select_branch_popup.hide(); } } + Action::ForcePush(branch, force) => self + .queue + .borrow_mut() + .push_back(InternalEvent::Push(branch, force)), }, InternalEvent::ConfirmAction(action) => { self.reset.open(action)?; diff --git a/src/components/reset.rs b/src/components/reset.rs index da275c5948..54bfc89771 100644 --- a/src/components/reset.rs +++ b/src/components/reset.rs @@ -160,6 +160,15 @@ impl ResetComponent { branch_ref, ), ), + Action::ForcePush(branch, _force) => ( + strings::confirm_title_force_push( + &self.key_config, + ), + strings::confirm_msg_force_push( + &self.key_config, + branch, + ), + ), }; } diff --git a/src/queue.rs b/src/queue.rs index 0430c45b81..dc9c650378 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -29,6 +29,7 @@ pub enum Action { ResetHunk(String, u64), StashDrop(CommitId), DeleteBranch(String), + ForcePush(String, bool), } /// diff --git a/src/strings.rs b/src/strings.rs index 603d46446d..620bbcf1da 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -102,6 +102,20 @@ pub fn confirm_msg_delete_branch( ) -> String { format!("Confirm deleting branch: '{}' ?", branch_ref) } +pub fn confirm_title_force_push( + _key_config: &SharedKeyConfig, +) -> String { + "Force Push".to_string() +} +pub fn confirm_msg_force_push( + _key_config: &SharedKeyConfig, + branch_ref: &str, +) -> String { + format!( + "Confirm force push to branch '{}' ? This may rewrite history.", + branch_ref + ) +} pub fn log_title(_key_config: &SharedKeyConfig) -> String { "Commit".to_string() } diff --git a/src/tabs/status.rs b/src/tabs/status.rs index b4f47a92ec..57ff179c2b 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -6,7 +6,7 @@ use crate::{ DiffComponent, DrawableComponent, FileTreeItemKind, }, keys::SharedKeyConfig, - queue::{InternalEvent, Queue, ResetItem}, + queue::{Action, InternalEvent, Queue, ResetItem}, strings::{self, order}, ui::style::SharedTheme, }; @@ -372,9 +372,17 @@ impl Status { if let Some(branch) = self.git_branch_name.last() { let branch = format!("refs/heads/{}", branch); - self.queue - .borrow_mut() - .push_back(InternalEvent::Push(branch, force)); + if force { + self.queue.borrow_mut().push_back( + InternalEvent::ConfirmAction(Action::ForcePush( + branch, force, + )), + ); + } else { + self.queue + .borrow_mut() + .push_back(InternalEvent::Push(branch, force)); + } } } From e369ed6a4d651a32078787afb56aab1993f2a1d8 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Fri, 13 Nov 2020 00:31:01 +0000 Subject: [PATCH 09/26] Increase size of confirm popup --- src/components/reset.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/reset.rs b/src/components/reset.rs index 54bfc89771..5a4de046fa 100644 --- a/src/components/reset.rs +++ b/src/components/reset.rs @@ -38,7 +38,7 @@ impl DrawableComponent for ResetComponent { self.theme.text_danger(), )]; - let area = ui::centered_rect(30, 20, f.size()); + let area = ui::centered_rect(50, 20, f.size()); f.render_widget(Clear, area); f.render_widget( popup_paragraph(&title, txt, &self.theme, true), From 9cfd9850776f72d9458981ca93c94940b6387a86 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Fri, 13 Nov 2020 00:38:46 +0000 Subject: [PATCH 10/26] Remove refs/head/ from force push message --- src/components/reset.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/reset.rs b/src/components/reset.rs index 5a4de046fa..b1f7537bdc 100644 --- a/src/components/reset.rs +++ b/src/components/reset.rs @@ -166,7 +166,7 @@ impl ResetComponent { ), strings::confirm_msg_force_push( &self.key_config, - branch, + branch.rsplit('/').next().expect("There was no / in the head reference which is impossible in git"), ), ), }; From 1499c35d60698f63a2872adfd38bcf04ca1d8828 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Tue, 2 Feb 2021 21:59:31 +0000 Subject: [PATCH 11/26] Use key_config.get_hint in strings --- src/strings.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/strings.rs b/src/strings.rs index e8c61b5c19..1746279cd1 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -830,7 +830,7 @@ pub mod commands { CommandText::new( format!( "Force Push [{}]", - get_hint(key_config.force_push), + key_config.get_hint(key_config.force_push), ), "force push to origin", CMD_GROUP_GENERAL, From 3a6b9ebfb22788671fb940c15df6164ff617b86e Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Tue, 2 Feb 2021 22:03:46 +0000 Subject: [PATCH 12/26] Change vim_style_key_config force push --- assets/vim_style_key_config.ron | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/vim_style_key_config.ron b/assets/vim_style_key_config.ron index d341f12bb7..b1939ffcf8 100644 --- a/assets/vim_style_key_config.ron +++ b/assets/vim_style_key_config.ron @@ -68,7 +68,7 @@ select_branch: ( code: Char('b'), modifiers: ( bits: 0,),), delete_branch: ( code: Char('D'), modifiers: ( bits: 1,),), push: ( code: Char('p'), modifiers: ( bits: 0,),), - force_push: ( code: Char('p'), modifiers: ( bits: 2,),), + force_push: ( code: Char('P'), modifiers: ( bits: 1,),), fetch: ( code: Char('f'), modifiers: ( bits: 0,),), //removed in 0.11 From 6c6f95269ce4108f8e37888c91a15030b1463019 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Thu, 4 Feb 2021 23:20:52 +0000 Subject: [PATCH 13/26] First attempt at testing --- asyncgit/src/push.rs | 2 +- asyncgit/src/sync/mod.rs | 71 +++++++++++++++++++++++++++++++++ asyncgit/src/sync/remotes.rs | 77 +++++++++++++++++++++++++++++++++++- 3 files changed, 147 insertions(+), 3 deletions(-) diff --git a/asyncgit/src/push.rs b/asyncgit/src/push.rs index de970e57c5..42d8ebc91e 100644 --- a/asyncgit/src/push.rs +++ b/asyncgit/src/push.rs @@ -168,7 +168,7 @@ impl AsyncPush { params.branch.as_str(), params.force, params.basic_credential, - progress_sender.clone(), + Some(progress_sender.clone()), ); progress_sender diff --git a/asyncgit/src/sync/mod.rs b/asyncgit/src/sync/mod.rs index 618039b86a..1062ed0175 100644 --- a/asyncgit/src/sync/mod.rs +++ b/asyncgit/src/sync/mod.rs @@ -98,6 +98,77 @@ mod tests { Ok((td, repo)) } + /// The upstream is pre-set for the repo + pub fn upstream_repo_init() -> Result<( + TempDir, + Repository, + TempDir, + Repository, + TempDir, + Repository, + )> { + use crate::sync::branch::branch_set_upstream; + + let tmp_repo_dir = TempDir::new()?; + let tmp_other_repo_dir = TempDir::new()?; + let tmp_upstream_dir = TempDir::new()?; + let repo = Repository::init(tmp_repo_dir.path())?; + let other_repo = Repository::init(tmp_repo_dir.path())?; + let upstream = Repository::init(tmp_upstream_dir.path())?; + repo.remote( + "origin", + tmp_upstream_dir.path().to_str().unwrap(), + )?; + { + let mut config = repo.config()?; + config.set_str("user.name", "name")?; + config.set_str("user.email", "email")?; + + let mut index = repo.index()?; + let id = index.write_tree()?; + + let tree = repo.find_tree(id)?; + let sig = repo.signature()?; + repo.commit( + Some("HEAD"), + &sig, + &sig, + "initial", + &tree, + &[], + )?; + + let mut config = other_repo.config()?; + config.set_str("user.name", "name")?; + config.set_str("user.email", "email")?; + + let mut index = other_repo.index()?; + let id = index.write_tree()?; + + let tree = other_repo.find_tree(id)?; + let sig = other_repo.signature()?; + other_repo.commit( + Some("HEAD"), + &sig, + &sig, + "initial", + &tree, + &[], + )?; + + branch_set_upstream(&repo, "master")?; + branch_set_upstream(&other_repo, "master")?; + } + Ok(( + tmp_repo_dir, + repo, + tmp_upstream_dir, + upstream, + tmp_other_repo_dir, + other_repo, + )) + } + /// helper returning amount of files with changes in the (wd,stage) pub fn get_statuses(repo_path: &str) -> (usize, usize) { ( diff --git a/asyncgit/src/sync/remotes.rs b/asyncgit/src/sync/remotes.rs index 1c413f934d..3160e11286 100644 --- a/asyncgit/src/sync/remotes.rs +++ b/asyncgit/src/sync/remotes.rs @@ -113,7 +113,7 @@ pub fn push( branch: &str, force: bool, basic_credential: Option, - progress_sender: Sender, + progress_sender: Option>, ) -> Result<()> { scope_time!("push"); @@ -123,7 +123,7 @@ pub fn push( let mut options = PushOptions::new(); options.remote_callbacks(remote_callbacks( - Some(progress_sender), + progress_sender, basic_credential, )); options.packbuilder_parallelism(0); @@ -312,4 +312,77 @@ mod tests { .unwrap(); assert_eq!(first, String::from("origin")); } + + #[test] + fn test_force_push() { + use super::push; + use crate::sync::tests::upstream_repo_init; + use std::fs::File; + use std::io::Write; + + let ( + tmp_repo_dir, + repo, + tmp_upstream_dir, + upstream, + tmp_other_repo_dir, + other_repo, + ) = upstream_repo_init().expect("Failed to create co"); + + let tmp_repo_file_path = + tmp_repo_dir.path().join("temp_file.txt"); + let mut tmp_repo_file = + File::create(tmp_repo_file_path).unwrap(); + writeln!(tmp_repo_file, "TempSomething").unwrap(); + + let mut index = repo.index().unwrap(); + let id = index.write_tree().unwrap(); + + let tree = repo.find_tree(id).unwrap(); + let sig = repo.signature().unwrap(); + repo.commit(Some("HEAD"), &sig, &sig, "next", &tree, &[]) + .unwrap(); + + push( + tmp_repo_dir.path().to_str().unwrap(), + "origin", + "master", + false, + None, + None, + ) + .unwrap(); + + let tmp_repo_file_path = + tmp_repo_dir.path().join("temp_file.txt"); + let mut tmp_repo_file = + File::create(tmp_repo_file_path).unwrap(); + writeln!(tmp_repo_file, "TempElse").unwrap(); + + assert_eq!( + push( + tmp_other_repo_dir.path().to_str().unwrap(), + "origin", + "master", + false, + None, + None, + ) + .is_err(), + true + ); + + assert_eq!( + push( + tmp_other_repo_dir.path().to_str().unwrap(), + "origin", + "master", + true, + None, + None, + ) + .is_err(), + false + ); + } } From e562a17ca86929fdbbfd2b5a4c41167e08068372 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Fri, 5 Feb 2021 00:01:50 +0000 Subject: [PATCH 14/26] Work on testing --- asyncgit/src/sync/mod.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/asyncgit/src/sync/mod.rs b/asyncgit/src/sync/mod.rs index 1062ed0175..7e72b366bc 100644 --- a/asyncgit/src/sync/mod.rs +++ b/asyncgit/src/sync/mod.rs @@ -113,12 +113,19 @@ mod tests { let tmp_other_repo_dir = TempDir::new()?; let tmp_upstream_dir = TempDir::new()?; let repo = Repository::init(tmp_repo_dir.path())?; - let other_repo = Repository::init(tmp_repo_dir.path())?; - let upstream = Repository::init(tmp_upstream_dir.path())?; + let other_repo = Repository::init(tmp_other_repo_dir.path())?; + let upstream = + Repository::init_bare(tmp_upstream_dir.path())?; repo.remote( "origin", tmp_upstream_dir.path().to_str().unwrap(), )?; + + other_repo.remote( + "origin", + tmp_upstream_dir.path().to_str().unwrap(), + )?; + { let mut config = repo.config()?; config.set_str("user.name", "name")?; @@ -127,6 +134,9 @@ mod tests { let mut index = repo.index()?; let id = index.write_tree()?; + let root = repo.path().parent().unwrap(); + let repo_path = root.as_os_str().to_str().unwrap(); + let tree = repo.find_tree(id)?; let sig = repo.signature()?; repo.commit( @@ -137,7 +147,8 @@ mod tests { &tree, &[], )?; - + } + { let mut config = other_repo.config()?; config.set_str("user.name", "name")?; config.set_str("user.email", "email")?; @@ -155,10 +166,12 @@ mod tests { &tree, &[], )?; - - branch_set_upstream(&repo, "master")?; - branch_set_upstream(&other_repo, "master")?; } + + branch_set_upstream(&repo, "master")?; + branch_set_upstream(&other_repo, "master")?; + println!("Set Upstream"); + Ok(( tmp_repo_dir, repo, From 394a02e7d167164cafa51b8e4285499acb9ae646 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Fri, 5 Feb 2021 16:51:02 +0000 Subject: [PATCH 15/26] Correct error message on test setup --- asyncgit/src/sync/remotes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asyncgit/src/sync/remotes.rs b/asyncgit/src/sync/remotes.rs index 3160e11286..25a7f2da80 100644 --- a/asyncgit/src/sync/remotes.rs +++ b/asyncgit/src/sync/remotes.rs @@ -327,7 +327,7 @@ mod tests { upstream, tmp_other_repo_dir, other_repo, - ) = upstream_repo_init().expect("Failed to create co"); + ) = upstream_repo_init().expect("Failed to setup"); let tmp_repo_file_path = tmp_repo_dir.path().join("temp_file.txt"); From a0fe96ec6ace0e33b5e62951112de4a19926a1f7 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Sat, 6 Feb 2021 00:05:23 +0000 Subject: [PATCH 16/26] Fix force-push test --- asyncgit/src/sync/mod.rs | 6 +++--- asyncgit/src/sync/remotes.rs | 33 ++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/asyncgit/src/sync/mod.rs b/asyncgit/src/sync/mod.rs index 7e72b366bc..9ab2d3f6ca 100644 --- a/asyncgit/src/sync/mod.rs +++ b/asyncgit/src/sync/mod.rs @@ -107,7 +107,7 @@ mod tests { TempDir, Repository, )> { - use crate::sync::branch::branch_set_upstream; + // use crate::sync::branch::branch_set_upstream; let tmp_repo_dir = TempDir::new()?; let tmp_other_repo_dir = TempDir::new()?; @@ -168,8 +168,8 @@ mod tests { )?; } - branch_set_upstream(&repo, "master")?; - branch_set_upstream(&other_repo, "master")?; + //branch_set_upstream(&repo, "master")?; + //branch_set_upstream(&other_repo, "master")?; println!("Set Upstream"); Ok(( diff --git a/asyncgit/src/sync/remotes.rs b/asyncgit/src/sync/remotes.rs index 25a7f2da80..1dc02d9538 100644 --- a/asyncgit/src/sync/remotes.rs +++ b/asyncgit/src/sync/remotes.rs @@ -320,6 +320,12 @@ mod tests { use std::fs::File; use std::io::Write; + use crate::sync::commit::commit; + + // This test mimics the scenario of 2 people having 2 + // local branches and both modifying the same file then + // both pushing, sequentially + let ( tmp_repo_dir, repo, @@ -335,12 +341,7 @@ mod tests { File::create(tmp_repo_file_path).unwrap(); writeln!(tmp_repo_file, "TempSomething").unwrap(); - let mut index = repo.index().unwrap(); - let id = index.write_tree().unwrap(); - - let tree = repo.find_tree(id).unwrap(); - let sig = repo.signature().unwrap(); - repo.commit(Some("HEAD"), &sig, &sig, "next", &tree, &[]) + commit(tmp_repo_dir.path().to_str().unwrap(), "some") .unwrap(); push( @@ -353,12 +354,20 @@ mod tests { ) .unwrap(); - let tmp_repo_file_path = - tmp_repo_dir.path().join("temp_file.txt"); - let mut tmp_repo_file = - File::create(tmp_repo_file_path).unwrap(); - writeln!(tmp_repo_file, "TempElse").unwrap(); + let tmp_other_repo_file_path = + tmp_other_repo_dir.path().join("temp_file.txt"); + let mut tmp_other_repo_file = + File::create(tmp_other_repo_file_path).unwrap(); + writeln!(tmp_other_repo_file, "TempElse").unwrap(); + + commit( + tmp_other_repo_dir.path().to_str().unwrap(), + "someElse", + ) + .unwrap(); + // Attempt a normal push, + // should fail as branches diverged assert_eq!( push( tmp_other_repo_dir.path().to_str().unwrap(), @@ -372,6 +381,8 @@ mod tests { true ); + // Attempt force push, + // should work as it forces the push through assert_eq!( push( tmp_other_repo_dir.path().to_str().unwrap(), From 2d55df7017ef8edcf9855a191b644f5109416535 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Sat, 6 Feb 2021 00:13:49 +0000 Subject: [PATCH 17/26] Improve test code and add comments --- asyncgit/src/sync/mod.rs | 7 +++++++ asyncgit/src/sync/remotes.rs | 35 +++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/asyncgit/src/sync/mod.rs b/asyncgit/src/sync/mod.rs index 9ab2d3f6ca..ced57a1665 100644 --- a/asyncgit/src/sync/mod.rs +++ b/asyncgit/src/sync/mod.rs @@ -98,6 +98,13 @@ mod tests { Ok((td, repo)) } + /// Same as repo_init, but the repo is a bare repo (--bare) + pub fn repo_init_bare() -> Result<(TempDir, Repository)> { + let tmp_repo_dir = TempDir::new()?; + let bare_repo = Repository::init_bare(tmp_repo_dir.path())?; + Ok((tmp_repo_dir, bare_repo)) + } + /// The upstream is pre-set for the repo pub fn upstream_repo_init() -> Result<( TempDir, diff --git a/asyncgit/src/sync/remotes.rs b/asyncgit/src/sync/remotes.rs index 1dc02d9538..bb5db829f6 100644 --- a/asyncgit/src/sync/remotes.rs +++ b/asyncgit/src/sync/remotes.rs @@ -316,24 +316,32 @@ mod tests { #[test] fn test_force_push() { use super::push; - use crate::sync::tests::upstream_repo_init; use std::fs::File; use std::io::Write; use crate::sync::commit::commit; + use crate::sync::tests::{repo_init, repo_init_bare}; // This test mimics the scenario of 2 people having 2 // local branches and both modifying the same file then // both pushing, sequentially - let ( - tmp_repo_dir, - repo, - tmp_upstream_dir, - upstream, - tmp_other_repo_dir, - other_repo, - ) = upstream_repo_init().expect("Failed to setup"); + let (tmp_repo_dir, repo) = repo_init().unwrap(); + let (tmp_other_repo_dir, other_repo) = repo_init().unwrap(); + let (tmp_upstream_dir, upstream) = repo_init_bare().unwrap(); + + repo.remote( + "origin", + tmp_upstream_dir.path().to_str().unwrap(), + ) + .unwrap(); + + other_repo + .remote( + "origin", + tmp_upstream_dir.path().to_str().unwrap(), + ) + .unwrap(); let tmp_repo_file_path = tmp_repo_dir.path().join("temp_file.txt"); @@ -341,8 +349,11 @@ mod tests { File::create(tmp_repo_file_path).unwrap(); writeln!(tmp_repo_file, "TempSomething").unwrap(); - commit(tmp_repo_dir.path().to_str().unwrap(), "some") - .unwrap(); + commit( + tmp_repo_dir.path().to_str().unwrap(), + "repo_1_commit", + ) + .unwrap(); push( tmp_repo_dir.path().to_str().unwrap(), @@ -362,7 +373,7 @@ mod tests { commit( tmp_other_repo_dir.path().to_str().unwrap(), - "someElse", + "repo_2_commit", ) .unwrap(); From 3d31fcd6c38e1f5519b101dce1b57052b766a20a Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Sat, 6 Feb 2021 00:14:56 +0000 Subject: [PATCH 18/26] Remove unessessary function --- asyncgit/src/sync/remotes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asyncgit/src/sync/remotes.rs b/asyncgit/src/sync/remotes.rs index bb5db829f6..6689a389ad 100644 --- a/asyncgit/src/sync/remotes.rs +++ b/asyncgit/src/sync/remotes.rs @@ -328,7 +328,7 @@ mod tests { let (tmp_repo_dir, repo) = repo_init().unwrap(); let (tmp_other_repo_dir, other_repo) = repo_init().unwrap(); - let (tmp_upstream_dir, upstream) = repo_init_bare().unwrap(); + let (tmp_upstream_dir, _) = repo_init_bare().unwrap(); repo.remote( "origin", From 3df7ae8cef9c2146f15d8ad0abc72a70d2d998e5 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Sat, 6 Feb 2021 00:15:41 +0000 Subject: [PATCH 19/26] Remove unessessary function --- asyncgit/src/sync/mod.rs | 84 ---------------------------------------- 1 file changed, 84 deletions(-) diff --git a/asyncgit/src/sync/mod.rs b/asyncgit/src/sync/mod.rs index ced57a1665..231e7a51f7 100644 --- a/asyncgit/src/sync/mod.rs +++ b/asyncgit/src/sync/mod.rs @@ -105,90 +105,6 @@ mod tests { Ok((tmp_repo_dir, bare_repo)) } - /// The upstream is pre-set for the repo - pub fn upstream_repo_init() -> Result<( - TempDir, - Repository, - TempDir, - Repository, - TempDir, - Repository, - )> { - // use crate::sync::branch::branch_set_upstream; - - let tmp_repo_dir = TempDir::new()?; - let tmp_other_repo_dir = TempDir::new()?; - let tmp_upstream_dir = TempDir::new()?; - let repo = Repository::init(tmp_repo_dir.path())?; - let other_repo = Repository::init(tmp_other_repo_dir.path())?; - let upstream = - Repository::init_bare(tmp_upstream_dir.path())?; - repo.remote( - "origin", - tmp_upstream_dir.path().to_str().unwrap(), - )?; - - other_repo.remote( - "origin", - tmp_upstream_dir.path().to_str().unwrap(), - )?; - - { - let mut config = repo.config()?; - config.set_str("user.name", "name")?; - config.set_str("user.email", "email")?; - - let mut index = repo.index()?; - let id = index.write_tree()?; - - let root = repo.path().parent().unwrap(); - let repo_path = root.as_os_str().to_str().unwrap(); - - let tree = repo.find_tree(id)?; - let sig = repo.signature()?; - repo.commit( - Some("HEAD"), - &sig, - &sig, - "initial", - &tree, - &[], - )?; - } - { - let mut config = other_repo.config()?; - config.set_str("user.name", "name")?; - config.set_str("user.email", "email")?; - - let mut index = other_repo.index()?; - let id = index.write_tree()?; - - let tree = other_repo.find_tree(id)?; - let sig = other_repo.signature()?; - other_repo.commit( - Some("HEAD"), - &sig, - &sig, - "initial", - &tree, - &[], - )?; - } - - //branch_set_upstream(&repo, "master")?; - //branch_set_upstream(&other_repo, "master")?; - println!("Set Upstream"); - - Ok(( - tmp_repo_dir, - repo, - tmp_upstream_dir, - upstream, - tmp_other_repo_dir, - other_repo, - )) - } - /// helper returning amount of files with changes in the (wd,stage) pub fn get_statuses(repo_path: &str) -> (usize, usize) { ( From 53eab3688618aa1ad5880e20f2ac53f9fd9cc556 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Sat, 6 Feb 2021 00:47:20 +0000 Subject: [PATCH 20/26] Test that correct commits are in upstream --- asyncgit/src/sync/remotes.rs | 130 +++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/asyncgit/src/sync/remotes.rs b/asyncgit/src/sync/remotes.rs index 6689a389ad..4be0ccf78b 100644 --- a/asyncgit/src/sync/remotes.rs +++ b/asyncgit/src/sync/remotes.rs @@ -407,4 +407,134 @@ mod tests { false ); } + + #[test] + fn test_force_push_rewrites_history() { + use super::push; + use std::fs::File; + use std::io::Write; + + use crate::sync::commit::commit; + use crate::sync::tests::{repo_init, repo_init_bare}; + use crate::sync::LogWalker; + + // This test mimics the scenario of 2 people having 2 + // local branches and both modifying the same file then + // both pushing, sequentially + + let (tmp_repo_dir, repo) = repo_init().unwrap(); + let (tmp_other_repo_dir, other_repo) = repo_init().unwrap(); + let (tmp_upstream_dir, upstream) = repo_init_bare().unwrap(); + + repo.remote( + "origin", + tmp_upstream_dir.path().to_str().unwrap(), + ) + .unwrap(); + + other_repo + .remote( + "origin", + tmp_upstream_dir.path().to_str().unwrap(), + ) + .unwrap(); + + let tmp_repo_file_path = + tmp_repo_dir.path().join("temp_file.txt"); + let mut tmp_repo_file = + File::create(tmp_repo_file_path).unwrap(); + writeln!(tmp_repo_file, "TempSomething").unwrap(); + + commit( + tmp_repo_dir.path().to_str().unwrap(), + "repo_1_commit", + ) + .unwrap(); + + let mut repo_commit_ids = Vec::::new(); + LogWalker::new(&repo).read(&mut repo_commit_ids, 1); + + println!("repo {:?}", repo_commit_ids); + + let mut upstream_commit_ids = Vec::::new(); + LogWalker::new(&upstream).read(&mut upstream_commit_ids, 1); + + println!("upstream {:?}", upstream_commit_ids); + + push( + tmp_repo_dir.path().to_str().unwrap(), + "origin", + "master", + false, + None, + None, + ) + .unwrap(); + + let tmp_other_repo_file_path = + tmp_other_repo_dir.path().join("temp_file.txt"); + let mut tmp_other_repo_file = + File::create(tmp_other_repo_file_path).unwrap(); + writeln!(tmp_other_repo_file, "TempElse").unwrap(); + + commit( + tmp_other_repo_dir.path().to_str().unwrap(), + "repo_2_commit", + ) + .unwrap(); + let mut other_repo_commit_ids = Vec::::new(); + LogWalker::new(&other_repo) + .read(&mut other_repo_commit_ids, 1); + + println!("other repo {:?}", other_repo_commit_ids); + + // Attempt a normal push, + // should fail as branches diverged + assert_eq!( + push( + tmp_other_repo_dir.path().to_str().unwrap(), + "origin", + "master", + false, + None, + None, + ) + .is_err(), + true + ); + + // Check that the other commit is not in upstream, + // a normal push would not rewrite history + let mut commit_ids = Vec::::new(); + LogWalker::new(&upstream).read(&mut commit_ids, 1); + assert_eq!(commit_ids.contains(&repo_commit_ids[0]), true); + + println!(" upstream {:?}", commit_ids); + + // Attempt force push, + // should work as it forces the push through + assert_eq!( + push( + tmp_other_repo_dir.path().to_str().unwrap(), + "origin", + "master", + true, + None, + None, + ) + .is_err(), + false + ); + + LogWalker::new(&upstream).read(&mut commit_ids, 1); + + // Check that both the commits are now in upstream + assert_eq!( + commit_ids.contains(&repo_commit_ids[0]) + && commit_ids.contains(&other_repo_commit_ids[0]), + true + ); + + println!("upstream {:?}", commit_ids); + } } From 274ac47176bfc72f767a364b5c92a46e1fbb4104 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Sat, 6 Feb 2021 00:49:22 +0000 Subject: [PATCH 21/26] Unwrap logwalkers --- asyncgit/src/sync/remotes.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/asyncgit/src/sync/remotes.rs b/asyncgit/src/sync/remotes.rs index 4be0ccf78b..fc0edadfd4 100644 --- a/asyncgit/src/sync/remotes.rs +++ b/asyncgit/src/sync/remotes.rs @@ -452,15 +452,10 @@ mod tests { .unwrap(); let mut repo_commit_ids = Vec::::new(); - LogWalker::new(&repo).read(&mut repo_commit_ids, 1); + LogWalker::new(&repo).read(&mut repo_commit_ids, 1).unwrap(); println!("repo {:?}", repo_commit_ids); - let mut upstream_commit_ids = Vec::::new(); - LogWalker::new(&upstream).read(&mut upstream_commit_ids, 1); - - println!("upstream {:?}", upstream_commit_ids); - push( tmp_repo_dir.path().to_str().unwrap(), "origin", @@ -484,7 +479,8 @@ mod tests { .unwrap(); let mut other_repo_commit_ids = Vec::::new(); LogWalker::new(&other_repo) - .read(&mut other_repo_commit_ids, 1); + .read(&mut other_repo_commit_ids, 1) + .unwrap(); println!("other repo {:?}", other_repo_commit_ids); @@ -506,7 +502,7 @@ mod tests { // Check that the other commit is not in upstream, // a normal push would not rewrite history let mut commit_ids = Vec::::new(); - LogWalker::new(&upstream).read(&mut commit_ids, 1); + LogWalker::new(&upstream).read(&mut commit_ids, 1).unwrap(); assert_eq!(commit_ids.contains(&repo_commit_ids[0]), true); println!(" upstream {:?}", commit_ids); @@ -526,7 +522,7 @@ mod tests { false ); - LogWalker::new(&upstream).read(&mut commit_ids, 1); + LogWalker::new(&upstream).read(&mut commit_ids, 1).unwrap(); // Check that both the commits are now in upstream assert_eq!( From 23823580999ee5077ec724da7e2afd335b4c8e53 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Sat, 6 Feb 2021 11:36:50 +0000 Subject: [PATCH 22/26] Fix force-push test --- asyncgit/src/sync/remotes.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/asyncgit/src/sync/remotes.rs b/asyncgit/src/sync/remotes.rs index fc0edadfd4..352bf3ede0 100644 --- a/asyncgit/src/sync/remotes.rs +++ b/asyncgit/src/sync/remotes.rs @@ -522,12 +522,12 @@ mod tests { false ); + let mut commit_ids = Vec::::new(); LogWalker::new(&upstream).read(&mut commit_ids, 1).unwrap(); - // Check that both the commits are now in upstream + // Check that only the other repo commit is now in upstream assert_eq!( - commit_ids.contains(&repo_commit_ids[0]) - && commit_ids.contains(&other_repo_commit_ids[0]), + commit_ids.contains(&other_repo_commit_ids[0]), true ); From 2585af97b042ed8f46a31ff5a1d8f8e91984e2bf Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Sat, 6 Feb 2021 11:39:04 +0000 Subject: [PATCH 23/26] Clear rather than make new vec --- asyncgit/src/sync/remotes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asyncgit/src/sync/remotes.rs b/asyncgit/src/sync/remotes.rs index 352bf3ede0..e8f18110ee 100644 --- a/asyncgit/src/sync/remotes.rs +++ b/asyncgit/src/sync/remotes.rs @@ -522,7 +522,7 @@ mod tests { false ); - let mut commit_ids = Vec::::new(); + commit_ids.clear(); LogWalker::new(&upstream).read(&mut commit_ids, 1).unwrap(); // Check that only the other repo commit is now in upstream From 698d2bbbb1b7e9d4c5bf54d86f12c077714bd29e Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Sat, 6 Feb 2021 12:24:19 +0000 Subject: [PATCH 24/26] Test force push commit has same parent as original --- asyncgit/src/sync/remotes.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/asyncgit/src/sync/remotes.rs b/asyncgit/src/sync/remotes.rs index e8f18110ee..edbd5e54ba 100644 --- a/asyncgit/src/sync/remotes.rs +++ b/asyncgit/src/sync/remotes.rs @@ -466,6 +466,14 @@ mod tests { ) .unwrap(); + let upstream_parent = upstream + .find_commit((repo_commit_ids[0]).into()) + .unwrap() + .parents() + .next() + .unwrap() + .id(); + let tmp_other_repo_file_path = tmp_other_repo_dir.path().join("temp_file.txt"); let mut tmp_other_repo_file = @@ -524,6 +532,16 @@ mod tests { commit_ids.clear(); LogWalker::new(&upstream).read(&mut commit_ids, 1).unwrap(); + let c = upstream.find_commit((commit_ids[0]).into()).unwrap(); + + assert_eq!( + c.parents().next().unwrap().id() == upstream_parent, + true + ); + println!( + "upstream {:?}", + c.parents().collect::>()[0].id() + ); // Check that only the other repo commit is now in upstream assert_eq!( From 0238ceba98ee3c5c937165ff8a9b9b2111771d22 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Sat, 6 Feb 2021 12:25:31 +0000 Subject: [PATCH 25/26] Remove print statements --- asyncgit/src/sync/remotes.rs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/asyncgit/src/sync/remotes.rs b/asyncgit/src/sync/remotes.rs index edbd5e54ba..434199585f 100644 --- a/asyncgit/src/sync/remotes.rs +++ b/asyncgit/src/sync/remotes.rs @@ -454,8 +454,6 @@ mod tests { let mut repo_commit_ids = Vec::::new(); LogWalker::new(&repo).read(&mut repo_commit_ids, 1).unwrap(); - println!("repo {:?}", repo_commit_ids); - push( tmp_repo_dir.path().to_str().unwrap(), "origin", @@ -490,8 +488,6 @@ mod tests { .read(&mut other_repo_commit_ids, 1) .unwrap(); - println!("other repo {:?}", other_repo_commit_ids); - // Attempt a normal push, // should fail as branches diverged assert_eq!( @@ -513,8 +509,6 @@ mod tests { LogWalker::new(&upstream).read(&mut commit_ids, 1).unwrap(); assert_eq!(commit_ids.contains(&repo_commit_ids[0]), true); - println!(" upstream {:?}", commit_ids); - // Attempt force push, // should work as it forces the push through assert_eq!( @@ -534,21 +528,15 @@ mod tests { LogWalker::new(&upstream).read(&mut commit_ids, 1).unwrap(); let c = upstream.find_commit((commit_ids[0]).into()).unwrap(); + // Check that only the other repo commit is now in upstream assert_eq!( - c.parents().next().unwrap().id() == upstream_parent, + commit_ids.contains(&other_repo_commit_ids[0]), true ); - println!( - "upstream {:?}", - c.parents().collect::>()[0].id() - ); - // Check that only the other repo commit is now in upstream assert_eq!( - commit_ids.contains(&other_repo_commit_ids[0]), + c.parents().next().unwrap().id() == upstream_parent, true ); - - println!("upstream {:?}", commit_ids); } } From 415f321ce8dae353314349668846b2311446cc52 Mon Sep 17 00:00:00 2001 From: Richard Menzies Date: Sat, 6 Feb 2021 12:26:42 +0000 Subject: [PATCH 26/26] Small improvement --- asyncgit/src/sync/remotes.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/asyncgit/src/sync/remotes.rs b/asyncgit/src/sync/remotes.rs index 434199585f..f7a762e2d0 100644 --- a/asyncgit/src/sync/remotes.rs +++ b/asyncgit/src/sync/remotes.rs @@ -526,7 +526,6 @@ mod tests { commit_ids.clear(); LogWalker::new(&upstream).read(&mut commit_ids, 1).unwrap(); - let c = upstream.find_commit((commit_ids[0]).into()).unwrap(); // Check that only the other repo commit is now in upstream assert_eq!( @@ -535,7 +534,14 @@ mod tests { ); assert_eq!( - c.parents().next().unwrap().id() == upstream_parent, + upstream + .find_commit((commit_ids[0]).into()) + .unwrap() + .parents() + .next() + .unwrap() + .id() + == upstream_parent, true ); }