Skip to content

Commit

Permalink
feat(revset): create main() function
Browse files Browse the repository at this point in the history
  • Loading branch information
arxanas committed Oct 3, 2022
1 parent f763add commit cab88fa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions git-branchless/src/revset/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ lazy_static! {
("roots", &fn_roots),
("heads", &fn_heads),
("branches", &fn_branches),
("main", &fn_main),
("public", &fn_public),
("draft", &fn_draft),
("stack", &fn_stack),
Expand Down Expand Up @@ -173,6 +174,11 @@ fn fn_nthancestor(ctx: &mut Context, name: &str, args: &[Expr]) -> EvalResult {
Ok(CommitSet::from_iter(result.into_iter()))
}

fn fn_main(ctx: &mut Context, name: &str, args: &[Expr]) -> EvalResult {
eval0(ctx, name, args)?;
Ok(ctx.dag.main_branch_commit.clone())
}

fn fn_public(ctx: &mut Context, name: &str, args: &[Expr]) -> EvalResult {
eval0(ctx, name, args)?;
let public_commits = ctx.query_public_commits()?;
Expand Down
16 changes: 16 additions & 0 deletions git-branchless/src/revset/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,22 @@ mod tests {
"###);
}

{
let expr = Expr::FunctionCall(Cow::Borrowed("main"), vec![]);
insta::assert_debug_snapshot!(eval_and_sort(&effects, &repo, &mut dag, &expr), @r###"
Ok(
[
Commit {
inner: Commit {
id: bf0d52a607f693201512a43b6b5a70b2a275e0ad,
summary: "create test4.txt",
},
},
],
)
"###);
}

{
let expr = Expr::FunctionCall(Cow::Borrowed("public"), vec![]);
insta::assert_debug_snapshot!(eval_and_sort(&effects, &repo, &mut dag, &expr), @r###"
Expand Down
2 changes: 1 addition & 1 deletion git-branchless/tests/command/test_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn test_query_eval_error() -> eyre::Result<()> {
..Default::default()
},
)?;
insta::assert_snapshot!(stderr, @"Evaluation error for expression 'foo()': no function with the name 'foo' could be found; these functions are available: all, ancestors, ancestors.nth, author.date, author.email, author.name, branches, children, committer.date, committer.email, committer.name, descendants, difference, draft, exactly, heads, intersection, message, none, not, only, parents, parents.nth, paths.changed, public, range, roots, stack, union
insta::assert_snapshot!(stderr, @"Evaluation error for expression 'foo()': no function with the name 'foo' could be found; these functions are available: all, ancestors, ancestors.nth, author.date, author.email, author.name, branches, children, committer.date, committer.email, committer.name, descendants, difference, draft, exactly, heads, intersection, main, message, none, not, only, parents, parents.nth, paths.changed, public, range, roots, stack, union
");
insta::assert_snapshot!(stdout, @"");
}
Expand Down

0 comments on commit cab88fa

Please sign in to comment.