summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Wernick <justin@jemstep.com>2020-03-17 16:54:08 +0200
committerGitHub <noreply@github.com>2020-03-17 16:54:08 +0200
commitc6eaa9bd05dccebce945e3fe0bfb9726b939ca11 (patch)
tree9eee065e7956d4104c878bb18a177c4dc0574354
parent472f52b3b78168013038c2c67ee7981684a566f9 (diff)
parent890e6898447fa5a00cbe27b27cbb3c6e0fa75b4f (diff)
Merge pull request #50 from jemstep/PYKE-11910-Enforce-Rebasing
Pyke 11910 enforce rebasing
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/git.rs53
-rw-r--r--tests/test-repo.git/objects/75/356231c60e1ae30d214b70a66242dfc02c84f7bin0 -> 414 bytes
-rw-r--r--tests/test-repo.git/objects/c7/b66e0ba25bedd6bc39efc7b6299d2ccd2d6d71bin0 -> 108 bytes
-rw-r--r--tests/test-repo.git/refs/tags/lightweight-tag1
6 files changed, 53 insertions, 5 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7a76226..bf5e8c2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -45,7 +45,7 @@ dependencies = [
[[package]]
name = "capn"
-version = "0.5.0"
+version = "0.5.1"
dependencies = [
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"git2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index e577f73..bcb0dda 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "capn"
-version = "0.5.0"
+version = "0.5.1"
authors = ["Justin Wernick <justin@jemstep.com>"]
edition = "2018"
diff --git a/src/git.rs b/src/git.rs
index de0854c..252b21d 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -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
new file mode 100644
index 0000000..423936c
--- /dev/null
+++ b/tests/test-repo.git/objects/75/356231c60e1ae30d214b70a66242dfc02c84f7
Binary files differ
diff --git a/tests/test-repo.git/objects/c7/b66e0ba25bedd6bc39efc7b6299d2ccd2d6d71 b/tests/test-repo.git/objects/c7/b66e0ba25bedd6bc39efc7b6299d2ccd2d6d71
new file mode 100644
index 0000000..ba2ad2c
--- /dev/null
+++ b/tests/test-repo.git/objects/c7/b66e0ba25bedd6bc39efc7b6299d2ccd2d6d71
Binary files differ
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