diff options
author | Justin Worthe <justin@jemstep.com> | 2020-03-16 16:27:51 +0200 |
---|---|---|
committer | Justin Worthe <justin@jemstep.com> | 2020-03-16 16:49:33 +0200 |
commit | 6162eb8d724e48f5d2d4522827fd7fbe6964120f (patch) | |
tree | 80fc6b7a518633ba41527069370d2aa805a09483 | |
parent | 472f52b3b78168013038c2c67ee7981684a566f9 (diff) |
PYKE-11910: Fixed is_tag test to not error if the tag doesn't exist yet
-rw-r--r-- | src/git.rs | 53 | ||||
-rw-r--r-- | tests/test-repo.git/objects/75/356231c60e1ae30d214b70a66242dfc02c84f7 | bin | 0 -> 414 bytes | |||
-rw-r--r-- | tests/test-repo.git/objects/c7/b66e0ba25bedd6bc39efc7b6299d2ccd2d6d71 | bin | 0 -> 108 bytes | |||
-rw-r--r-- | tests/test-repo.git/refs/tags/lightweight-tag | 1 |
4 files changed, 51 insertions, 3 deletions
@@ -1,7 +1,7 @@ use crate::error::CapnError; use crate::keyring::Keyring; use git2; -use git2::{ErrorClass, ObjectType, Oid, Repository}; +use git2::{ErrorClass, ErrorCode, ObjectType, Oid, Repository}; use std::cell::RefCell; use std::collections::HashMap; use std::error::Error; @@ -388,8 +388,11 @@ impl Git for LiveGit { } fn is_tag(&self, ref_name: &str) -> Result<bool, Box<dyn Error>> { - let reference = self.repo.find_reference(ref_name)?; - Ok(reference.is_tag()) + match self.repo.find_reference(ref_name) { + Ok(reference) => Ok(reference.is_tag()), + Err(err) if err.code() == ErrorCode::NotFound => Ok(ref_name.starts_with("refs/tags")), + Err(e) => Err(e.into()), + } } fn is_descendent_of(&self, commit: Oid, ancestor: Oid) -> Result<bool, Box<dyn Error>> { @@ -595,6 +598,50 @@ mod test { } } + mod is_tag { + use super::super::*; + + #[test] + fn identifies_existing_branch_as_not_a_tag() { + let project_root = env!("CARGO_MANIFEST_DIR"); + let git = LiveGit::default(format!("{}/tests/test-repo.git", project_root)).unwrap(); + assert_eq!(git.is_tag("refs/heads/master").ok(), Some(false)); + } + #[test] + fn identifies_new_branch_as_not_a_tag() { + let project_root = env!("CARGO_MANIFEST_DIR"); + let git = LiveGit::default(format!("{}/tests/test-repo.git", project_root)).unwrap(); + assert_eq!( + git.is_tag("refs/heads/new-brach-that-does-not-exist").ok(), + Some(false) + ); + } + #[test] + fn identifies_existing_lightweight_tag_as_a_tag() { + let project_root = env!("CARGO_MANIFEST_DIR"); + let git = LiveGit::default(format!("{}/tests/test-repo.git", project_root)).unwrap(); + assert_eq!(git.is_tag("refs/tags/lightweight-tag").ok(), Some(true)); + } + #[test] + fn identifies_existing_annotated_tag_as_a_tag() { + let project_root = env!("CARGO_MANIFEST_DIR"); + let git = LiveGit::default(format!("{}/tests/test-repo.git", project_root)).unwrap(); + assert_eq!( + git.is_tag("refs/tags/capn-override-test-user-1").ok(), + Some(true) + ); + } + #[test] + fn identifies_new_tag_as_a_tag() { + let project_root = env!("CARGO_MANIFEST_DIR"); + let git = LiveGit::default(format!("{}/tests/test-repo.git", project_root)).unwrap(); + assert_eq!( + git.is_tag("refs/tags/new-tag-that-does-not-exist").ok(), + Some(true) + ); + } + } + mod find_new_commits { use super::super::*; use git2::Oid; diff --git a/tests/test-repo.git/objects/75/356231c60e1ae30d214b70a66242dfc02c84f7 b/tests/test-repo.git/objects/75/356231c60e1ae30d214b70a66242dfc02c84f7 Binary files differnew file mode 100644 index 0000000..423936c --- /dev/null +++ b/tests/test-repo.git/objects/75/356231c60e1ae30d214b70a66242dfc02c84f7 diff --git a/tests/test-repo.git/objects/c7/b66e0ba25bedd6bc39efc7b6299d2ccd2d6d71 b/tests/test-repo.git/objects/c7/b66e0ba25bedd6bc39efc7b6299d2ccd2d6d71 Binary files differnew file mode 100644 index 0000000..ba2ad2c --- /dev/null +++ b/tests/test-repo.git/objects/c7/b66e0ba25bedd6bc39efc7b6299d2ccd2d6d71 diff --git a/tests/test-repo.git/refs/tags/lightweight-tag b/tests/test-repo.git/refs/tags/lightweight-tag new file mode 100644 index 0000000..567eaef --- /dev/null +++ b/tests/test-repo.git/refs/tags/lightweight-tag @@ -0,0 +1 @@ +75356231c60e1ae30d214b70a66242dfc02c84f7 |