From b53251925e8cf0393377633ec1012f0613e7c42b Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 8 Aug 2024 14:58:29 +0100 Subject: test(remote): `push` to existing proposal push 2 commits to an existing proposal there are a lot of asserts in here but if they were split out into their own tests the suite would take much longer to run as we are waiting a few seconds in the test to ensure the timestamps are different --- test_utils/src/git.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'test_utils') diff --git a/test_utils/src/git.rs b/test_utils/src/git.rs index f299b40..5ae7f39 100644 --- a/test_utils/src/git.rs +++ b/test_utils/src/git.rs @@ -8,7 +8,7 @@ use std::{ }; use anyhow::{Context, Result}; -use git2::{Oid, RepositoryInitOptions, Signature, Time}; +use git2::{Branch, Oid, RepositoryInitOptions, Signature, Time}; use nostr::nips::nip01::Coordinate; use nostr_sdk::{Kind, ToBech32}; @@ -214,10 +214,10 @@ impl GitTestRepo { Ok(oid) } - pub fn create_branch(&self, branch_name: &str) -> Result<()> { + pub fn create_branch(&self, branch_name: &str) -> Result { self.git_repo - .branch(branch_name, &self.git_repo.head()?.peel_to_commit()?, false)?; - Ok(()) + .branch(branch_name, &self.git_repo.head()?.peel_to_commit()?, false) + .context("could not create branch") } pub fn checkout(&self, ref_name: &str) -> Result { @@ -273,6 +273,14 @@ impl GitTestRepo { self.git_repo.remote(name, url)?; Ok(()) } + + pub fn checkout_remote_branch(&self, branch_name: &str) -> Result<()> { + self.checkout(&format!("remotes/origin/{branch_name}"))?; + let mut branch = self.create_branch(branch_name)?; + branch.set_upstream(Some(&format!("origin/{branch_name}")))?; + self.checkout(branch_name)?; + Ok(()) + } } impl Drop for GitTestRepo { -- cgit v1.2.3