Skip to content

Commit b9a4bdc

Browse files
committed
frame for basic parsing (#450)
1 parent 5c823dc commit b9a4bdc

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

git-refspec/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use bstr::{BStr, BString};
77
/// The way to interpret a refspec.
88
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
99
pub enum Mode {
10+
/// Apply standard rules for refspecs which are including refs with specific rules related to allowing fast forwards of destinations.
11+
Normal,
1012
/// Even though according to normal rules a non-fastforward would be denied, override this and reset a ref forcefully in the destination.
1113
Force,
1214
/// Instead of considering matching refs included, we consider them excluded. This applies only to the source side of a refspec.
@@ -40,6 +42,9 @@ pub struct RefSpec {
4042
dest: Option<BString>,
4143
}
4244

45+
pub mod parse;
46+
pub use parse::function::parse;
47+
4348
mod spec {
4449
use crate::{RefSpec, RefSpecRef};
4550

git-refspec/src/parse.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#[derive(Debug, thiserror::Error)]
2+
pub enum Error {
3+
#[error("Empty refspecs are invalid")]
4+
Empty,
5+
#[error("Negative refspecs cannot have destinations as they exclude sources")]
6+
NegativeWithDestination,
7+
}
8+
9+
pub(crate) mod function {
10+
use crate::parse::Error;
11+
use crate::{Operation, RefSpecRef};
12+
use bstr::BStr;
13+
14+
/// Parse `spec` for use in `operation` and return it if it is valid.
15+
pub fn parse(mut _spec: &BStr, _operation: Operation) -> Result<RefSpecRef<'_>, Error> {
16+
todo!()
17+
}
18+
}

git-refspec/tests/parse/mod.rs

+28
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,31 @@ use git_testtools::scripted_fixture_repo_read_only;
55
fn baseline() {
66
let _dir = scripted_fixture_repo_read_only("make_baseline.sh").unwrap();
77
}
8+
9+
mod invalid {
10+
use git_refspec::{parse, parse::Error, Operation};
11+
12+
#[test]
13+
#[ignore]
14+
fn empty() {
15+
assert!(matches!(parse("".into(), Operation::Fetch).unwrap_err(), Error::Empty));
16+
assert!(matches!(parse("".into(), Operation::Push).unwrap_err(), Error::Empty));
17+
}
18+
19+
#[test]
20+
#[ignore]
21+
fn negative_with_destination() {
22+
assert!(matches!(
23+
parse("^a:b".into(), Operation::Fetch).unwrap_err(),
24+
Error::NegativeWithDestination
25+
));
26+
assert!(matches!(
27+
parse("a:b".into(), Operation::Fetch).unwrap_err(),
28+
Error::NegativeWithDestination
29+
));
30+
}
31+
32+
mod fetch {}
33+
34+
mod push {}
35+
}

0 commit comments

Comments
 (0)