upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/test_utils/src/git.rs
diff options
context:
space:
mode:
Diffstat (limited to 'test_utils/src/git.rs')
-rw-r--r--test_utils/src/git.rs16
1 files changed, 12 insertions, 4 deletions
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::{
8}; 8};
9 9
10use anyhow::{Context, Result}; 10use anyhow::{Context, Result};
11use git2::{Oid, RepositoryInitOptions, Signature, Time}; 11use git2::{Branch, Oid, RepositoryInitOptions, Signature, Time};
12use nostr::nips::nip01::Coordinate; 12use nostr::nips::nip01::Coordinate;
13use nostr_sdk::{Kind, ToBech32}; 13use nostr_sdk::{Kind, ToBech32};
14 14
@@ -214,10 +214,10 @@ impl GitTestRepo {
214 Ok(oid) 214 Ok(oid)
215 } 215 }
216 216
217 pub fn create_branch(&self, branch_name: &str) -> Result<()> { 217 pub fn create_branch(&self, branch_name: &str) -> Result<Branch> {
218 self.git_repo 218 self.git_repo
219 .branch(branch_name, &self.git_repo.head()?.peel_to_commit()?, false)?; 219 .branch(branch_name, &self.git_repo.head()?.peel_to_commit()?, false)
220 Ok(()) 220 .context("could not create branch")
221 } 221 }
222 222
223 pub fn checkout(&self, ref_name: &str) -> Result<Oid> { 223 pub fn checkout(&self, ref_name: &str) -> Result<Oid> {
@@ -273,6 +273,14 @@ impl GitTestRepo {
273 self.git_repo.remote(name, url)?; 273 self.git_repo.remote(name, url)?;
274 Ok(()) 274 Ok(())
275 } 275 }
276
277 pub fn checkout_remote_branch(&self, branch_name: &str) -> Result<()> {
278 self.checkout(&format!("remotes/origin/{branch_name}"))?;
279 let mut branch = self.create_branch(branch_name)?;
280 branch.set_upstream(Some(&format!("origin/{branch_name}")))?;
281 self.checkout(branch_name)?;
282 Ok(())
283 }
276} 284}
277 285
278impl Drop for GitTestRepo { 286impl Drop for GitTestRepo {