Skip to content

Commit

Permalink
Implement :<path> parsing (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jun 9, 2022
1 parent d51e438 commit 74e7a46
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
11 changes: 11 additions & 0 deletions cargo-smart-release/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion git-revision/src/spec/parse/delegate.rs
Expand Up @@ -95,7 +95,10 @@ pub enum PeelTo<'a> {
/// The path to drill into as seen relative to the current tree-ish.
///
/// Note that the path can be relative, and `./` and `../` prefixes are seen as relative to the current
/// working directory
/// working directory.
///
/// The path may be empty, which makes it refer to the tree at the current revision, similar to `^{tree}`.
/// Note that paths like `../` are valid and refer to a tree as seen relative to the current working directory.
Path(&'a BStr),
}

Expand Down
7 changes: 6 additions & 1 deletion git-revision/src/spec/parse/function.rs
Expand Up @@ -300,7 +300,12 @@ fn navigate<'a>(input: &'a BStr, delegate: &mut impl Delegate) -> Result<&'a BSt
.ok_or(Error::Delegate)?;
}
}
b':' => todo!(":"),
b':' => {
delegate
.peel_until(delegate::PeelTo::Path(input[cursor..].as_bstr()))
.ok_or(Error::Delegate)?;
return Ok("".into());
}
_ => return Ok(input[cursor - 1..].as_bstr()),
}
}
Expand Down
14 changes: 11 additions & 3 deletions git-revision/tests/spec/parse/navigate.rs
Expand Up @@ -3,7 +3,6 @@ mod colon_symbol {
use git_revision::spec::parse::delegate::Traversal;

#[test]
#[ignore]
fn paths_consume_all_remaining_input_as_they_refer_to_blobs() {
let rec = parse("@:../relative/path...@^^~~");

Expand All @@ -24,13 +23,22 @@ mod colon_symbol {
let rec = parse("@:absolute/path^{tree}");
assert_eq!(
rec.peel_to,
vec![PeelTo::Path("absolute/path^{object}".into())],
vec![PeelTo::Path("absolute/path^{tree}".into())],
"this includes useful navigation like assertion of trees/blobs, we may make this possible in future but for now are as open as git"
);
}

#[test]
#[ignore]
fn empty_paths_refer_to_the_root_tree() {
let rec = parse("@:");

assert!(rec.kind.is_none());
assert_eq!(rec.get_ref(0), "HEAD");
assert_eq!(rec.peel_to, vec![PeelTo::Path("".into())]);
assert_eq!(rec.calls, 2);
}

#[test]
fn paths_have_to_be_last_but_stack_with_other_navigation() {
let rec = parse("HEAD@{1}~10^2^{commit}:README.md");

Expand Down

0 comments on commit 74e7a46

Please sign in to comment.