Skip to content

Commit

Permalink
frame for basic parsing (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 5, 2022
1 parent 5c823dc commit b9a4bdc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions git-refspec/src/lib.rs
Expand Up @@ -7,6 +7,8 @@ use bstr::{BStr, BString};
/// The way to interpret a refspec.
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
pub enum Mode {
/// Apply standard rules for refspecs which are including refs with specific rules related to allowing fast forwards of destinations.
Normal,
/// Even though according to normal rules a non-fastforward would be denied, override this and reset a ref forcefully in the destination.
Force,
/// Instead of considering matching refs included, we consider them excluded. This applies only to the source side of a refspec.
Expand Down Expand Up @@ -40,6 +42,9 @@ pub struct RefSpec {
dest: Option<BString>,
}

pub mod parse;
pub use parse::function::parse;

mod spec {
use crate::{RefSpec, RefSpecRef};

Expand Down
18 changes: 18 additions & 0 deletions git-refspec/src/parse.rs
@@ -0,0 +1,18 @@
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Empty refspecs are invalid")]
Empty,
#[error("Negative refspecs cannot have destinations as they exclude sources")]
NegativeWithDestination,
}

pub(crate) mod function {
use crate::parse::Error;
use crate::{Operation, RefSpecRef};
use bstr::BStr;

/// Parse `spec` for use in `operation` and return it if it is valid.
pub fn parse(mut _spec: &BStr, _operation: Operation) -> Result<RefSpecRef<'_>, Error> {
todo!()
}
}
28 changes: 28 additions & 0 deletions git-refspec/tests/parse/mod.rs
Expand Up @@ -5,3 +5,31 @@ use git_testtools::scripted_fixture_repo_read_only;
fn baseline() {
let _dir = scripted_fixture_repo_read_only("make_baseline.sh").unwrap();
}

mod invalid {
use git_refspec::{parse, parse::Error, Operation};

#[test]
#[ignore]
fn empty() {
assert!(matches!(parse("".into(), Operation::Fetch).unwrap_err(), Error::Empty));
assert!(matches!(parse("".into(), Operation::Push).unwrap_err(), Error::Empty));
}

#[test]
#[ignore]
fn negative_with_destination() {
assert!(matches!(
parse("^a:b".into(), Operation::Fetch).unwrap_err(),
Error::NegativeWithDestination
));
assert!(matches!(
parse("a:b".into(), Operation::Fetch).unwrap_err(),
Error::NegativeWithDestination
));
}

mod fetch {}

mod push {}
}

0 comments on commit b9a4bdc

Please sign in to comment.