diff options
Diffstat (limited to 'test_utils')
| -rw-r--r-- | test_utils/src/git.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/test_utils/src/git.rs b/test_utils/src/git.rs index 058eb31..f299b40 100644 --- a/test_utils/src/git.rs +++ b/test_utils/src/git.rs | |||
| @@ -17,6 +17,7 @@ use crate::generate_repo_ref_event; | |||
| 17 | pub struct GitTestRepo { | 17 | pub struct GitTestRepo { |
| 18 | pub dir: PathBuf, | 18 | pub dir: PathBuf, |
| 19 | pub git_repo: git2::Repository, | 19 | pub git_repo: git2::Repository, |
| 20 | pub delete_dir_on_drop: bool, | ||
| 20 | } | 21 | } |
| 21 | 22 | ||
| 22 | impl Default for GitTestRepo { | 23 | impl Default for GitTestRepo { |
| @@ -56,12 +57,22 @@ impl GitTestRepo { | |||
| 56 | Ok(Self { | 57 | Ok(Self { |
| 57 | dir: path, | 58 | dir: path, |
| 58 | git_repo, | 59 | git_repo, |
| 60 | delete_dir_on_drop: true, | ||
| 59 | }) | 61 | }) |
| 60 | } | 62 | } |
| 61 | pub fn without_repo_in_git_config() -> Self { | 63 | pub fn without_repo_in_git_config() -> Self { |
| 62 | Self::new("main").unwrap() | 64 | Self::new("main").unwrap() |
| 63 | } | 65 | } |
| 64 | 66 | ||
| 67 | pub fn open(path: &PathBuf) -> Result<Self> { | ||
| 68 | let git_repo = git2::Repository::open(path)?; | ||
| 69 | Ok(Self { | ||
| 70 | dir: path.clone(), | ||
| 71 | git_repo, | ||
| 72 | delete_dir_on_drop: true, | ||
| 73 | }) | ||
| 74 | } | ||
| 75 | |||
| 65 | pub fn duplicate(existing_repo: &GitTestRepo) -> Result<Self> { | 76 | pub fn duplicate(existing_repo: &GitTestRepo) -> Result<Self> { |
| 66 | let path = current_dir()?.join(format!("tmpgit-{}", rand::random::<u64>())); | 77 | let path = current_dir()?.join(format!("tmpgit-{}", rand::random::<u64>())); |
| 67 | // function source: https://stackoverflow.com/a/65192210 | 78 | // function source: https://stackoverflow.com/a/65192210 |
| @@ -86,6 +97,7 @@ impl GitTestRepo { | |||
| 86 | Ok(Self { | 97 | Ok(Self { |
| 87 | dir: path, | 98 | dir: path, |
| 88 | git_repo, | 99 | git_repo, |
| 100 | delete_dir_on_drop: true, | ||
| 89 | }) | 101 | }) |
| 90 | } | 102 | } |
| 91 | 103 | ||
| @@ -120,6 +132,7 @@ impl GitTestRepo { | |||
| 120 | Ok(Self { | 132 | Ok(Self { |
| 121 | dir: path, | 133 | dir: path, |
| 122 | git_repo, | 134 | git_repo, |
| 135 | delete_dir_on_drop: true, | ||
| 123 | }) | 136 | }) |
| 124 | } | 137 | } |
| 125 | 138 | ||
| @@ -129,6 +142,7 @@ impl GitTestRepo { | |||
| 129 | Ok(Self { | 142 | Ok(Self { |
| 130 | dir: path, | 143 | dir: path, |
| 131 | git_repo, | 144 | git_repo, |
| 145 | delete_dir_on_drop: true, | ||
| 132 | }) | 146 | }) |
| 133 | } | 147 | } |
| 134 | 148 | ||
| @@ -263,7 +277,9 @@ impl GitTestRepo { | |||
| 263 | 277 | ||
| 264 | impl Drop for GitTestRepo { | 278 | impl Drop for GitTestRepo { |
| 265 | fn drop(&mut self) { | 279 | fn drop(&mut self) { |
| 266 | let _ = fs::remove_dir_all(&self.dir); | 280 | if self.delete_dir_on_drop { |
| 281 | let _ = fs::remove_dir_all(&self.dir); | ||
| 282 | } | ||
| 267 | } | 283 | } |
| 268 | } | 284 | } |
| 269 | pub fn joe_signature() -> Signature<'static> { | 285 | pub fn joe_signature() -> Signature<'static> { |