diff options
Diffstat (limited to 'test_utils')
| -rw-r--r-- | test_utils/src/git.rs | 16 |
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 | ||
| 10 | use anyhow::{Context, Result}; | 10 | use anyhow::{Context, Result}; |
| 11 | use git2::{Oid, RepositoryInitOptions, Signature, Time}; | 11 | use git2::{Branch, Oid, RepositoryInitOptions, Signature, Time}; |
| 12 | use nostr::nips::nip01::Coordinate; | 12 | use nostr::nips::nip01::Coordinate; |
| 13 | use nostr_sdk::{Kind, ToBech32}; | 13 | use 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 | ||
| 278 | impl Drop for GitTestRepo { | 286 | impl Drop for GitTestRepo { |