2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2022 The Jujutsu Authors
|
2022-11-01 13:57:31 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2024-02-02 07:55:24 +00:00
|
|
|
use crate::common::TestEnvironment;
|
2022-11-01 13:57:31 +00:00
|
|
|
|
2022-11-16 07:47:00 +00:00
|
|
|
#[test]
|
|
|
|
fn test_syntax_error() {
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2022-11-16 07:47:00 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
2024-02-13 05:46:21 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", ":x"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: ':' is not a prefix operator
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:1
|
2024-02-13 05:46:21 +00:00
|
|
|
|
|
|
|
|
1 | :x
|
|
|
|
| ^
|
|
|
|
|
|
|
|
|
= ':' is not a prefix operator
|
|
|
|
Hint: Did you mean '::' for ancestors?
|
|
|
|
"###);
|
|
|
|
|
2022-11-16 07:47:00 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "x &"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Syntax error
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:4
|
2022-11-16 07:47:00 +00:00
|
|
|
|
|
|
|
|
1 | x &
|
|
|
|
| ^---
|
|
|
|
|
|
2023-09-07 01:11:48 +00:00
|
|
|
= expected `::`, `..`, `~`, or <primary>
|
2022-11-16 07:47:00 +00:00
|
|
|
"###);
|
2022-12-22 10:34:08 +00:00
|
|
|
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "x - y"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: '-' is not an infix operator
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:3
|
2022-12-22 10:34:08 +00:00
|
|
|
|
|
|
|
|
1 | x - y
|
|
|
|
| ^
|
|
|
|
|
|
2023-03-23 10:07:34 +00:00
|
|
|
= '-' is not an infix operator
|
|
|
|
Hint: Did you mean '~' for difference?
|
2022-12-22 10:34:08 +00:00
|
|
|
"###);
|
2022-12-22 11:18:25 +00:00
|
|
|
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "HEAD^"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: '^' is not a postfix operator
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:5
|
2022-12-22 11:18:25 +00:00
|
|
|
|
|
|
|
|
1 | HEAD^
|
|
|
|
| ^
|
|
|
|
|
|
2023-03-23 10:07:34 +00:00
|
|
|
= '^' is not a postfix operator
|
|
|
|
Hint: Did you mean '-' for parents?
|
2022-12-22 11:18:25 +00:00
|
|
|
"###);
|
2022-11-16 07:47:00 +00:00
|
|
|
}
|
|
|
|
|
2022-11-01 13:57:31 +00:00
|
|
|
#[test]
|
|
|
|
fn test_bad_function_call() {
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2022-11-01 13:57:31 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
revsets: allow `::` as synonym for `:`
The `--allow-large-revsets` flag we have on `jj rebase` and `jj new`
allows the user to do e.g. `jj rebase --allow-large-revsets -b
main.. -d main` to rebase all commits that are not in main onto
main. The reason we don't allow these revsets to resolve to multiple
commits by default is that we think users might specify multiple
commits by mistake. That's probably not much of a problem with `jj
rebase -b` (maybe we should always allow that to resolve to multiple
commits), but the user might want to know if `jj rebase -d @-`
resolves to multiple commits.
One problem with having a flag to allow multiple commits is that it
needs to be added to every command where we want to allow multiple
commits but default to one. Also, it should probably apply to each
revset argument those commands take. For example, even if the user
meant `-b main..` to resolve to multiple commits, they might not have
meant `-d main` to resolve to multiple commits (which it will in case
of a conflicted branch), so we might want separate
`--allow-large-revsets-in-destination` and
`--allow-large-revsets-in-source`, which gets quite cumbersome. It
seems better to have some syntax in the individual revsets for saying
that multiple commits are allowed.
One proposal I had was to use a `multiple()` revset function which
would have no effect in general but would be used as a marker if used
at the top level (e.g. `jj rebase -d 'multiple(@-)'`). After some
discussion on the PR adding that function (#1911), it seems that the
consensus is to instead use a prefix like `many:` or `all:`. That
avoids the problem with having a function that has no effect unless
it's used at the top level (`jj rebase -d 'multiple(x)|y'` would have
no effect).
Since we already have the `:` operator for DAG ranges, we need to
change it to make room for `many:`/`all:` syntax. This commit starts
that by allowing both `:` and `::`.
I have tried to update the documentation in this commit to either
mention both forms, or just the new and preferred `::` form. However,
it's useless to search for `:` in Rust code, so I'm sure I've missed
many instances. We'll have to address those as we notice them. I'll
let most tests use `:` until we deprecate it or delete it.
2023-07-27 23:27:44 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "all(or::nothing)"]);
|
2022-11-01 14:18:33 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Function "all": Expected 0 arguments
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:5
|
2022-11-01 14:18:33 +00:00
|
|
|
|
|
revsets: allow `::` as synonym for `:`
The `--allow-large-revsets` flag we have on `jj rebase` and `jj new`
allows the user to do e.g. `jj rebase --allow-large-revsets -b
main.. -d main` to rebase all commits that are not in main onto
main. The reason we don't allow these revsets to resolve to multiple
commits by default is that we think users might specify multiple
commits by mistake. That's probably not much of a problem with `jj
rebase -b` (maybe we should always allow that to resolve to multiple
commits), but the user might want to know if `jj rebase -d @-`
resolves to multiple commits.
One problem with having a flag to allow multiple commits is that it
needs to be added to every command where we want to allow multiple
commits but default to one. Also, it should probably apply to each
revset argument those commands take. For example, even if the user
meant `-b main..` to resolve to multiple commits, they might not have
meant `-d main` to resolve to multiple commits (which it will in case
of a conflicted branch), so we might want separate
`--allow-large-revsets-in-destination` and
`--allow-large-revsets-in-source`, which gets quite cumbersome. It
seems better to have some syntax in the individual revsets for saying
that multiple commits are allowed.
One proposal I had was to use a `multiple()` revset function which
would have no effect in general but would be used as a marker if used
at the top level (e.g. `jj rebase -d 'multiple(@-)'`). After some
discussion on the PR adding that function (#1911), it seems that the
consensus is to instead use a prefix like `many:` or `all:`. That
avoids the problem with having a function that has no effect unless
it's used at the top level (`jj rebase -d 'multiple(x)|y'` would have
no effect).
Since we already have the `:` operator for DAG ranges, we need to
change it to make room for `many:`/`all:` syntax. This commit starts
that by allowing both `:` and `::`.
I have tried to update the documentation in this commit to either
mention both forms, or just the new and preferred `::` form. However,
it's useless to search for `:` in Rust code, so I'm sure I've missed
many instances. We'll have to address those as we notice them. I'll
let most tests use `:` until we deprecate it or delete it.
2023-07-27 23:27:44 +00:00
|
|
|
1 | all(or::nothing)
|
|
|
|
| ^---------^
|
2022-11-01 14:18:33 +00:00
|
|
|
|
|
2024-03-26 11:28:50 +00:00
|
|
|
= Function "all": Expected 0 arguments
|
2022-11-01 14:18:33 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "parents()"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Function "parents": Expected 1 arguments
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:9
|
2022-11-01 14:18:33 +00:00
|
|
|
|
|
|
|
|
1 | parents()
|
|
|
|
| ^
|
|
|
|
|
|
2024-03-26 11:28:50 +00:00
|
|
|
= Function "parents": Expected 1 arguments
|
2022-11-01 14:18:33 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "parents(foo, bar)"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Function "parents": Expected 1 arguments
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:9
|
2022-11-01 14:18:33 +00:00
|
|
|
|
|
|
|
|
1 | parents(foo, bar)
|
|
|
|
| ^------^
|
|
|
|
|
|
2024-03-26 11:28:50 +00:00
|
|
|
= Function "parents": Expected 1 arguments
|
2022-11-01 14:18:33 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "heads(foo, bar)"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Function "heads": Expected 1 arguments
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:7
|
2022-11-01 14:18:33 +00:00
|
|
|
|
|
|
|
|
1 | heads(foo, bar)
|
|
|
|
| ^------^
|
|
|
|
|
|
2024-03-26 11:28:50 +00:00
|
|
|
= Function "heads": Expected 1 arguments
|
2022-11-01 14:18:33 +00:00
|
|
|
"###);
|
|
|
|
|
2023-03-25 03:14:26 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "latest(a, not_an_integer)"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Function "latest": Expected function argument of type integer
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:11
|
2023-03-25 03:14:26 +00:00
|
|
|
|
|
|
|
|
1 | latest(a, not_an_integer)
|
|
|
|
| ^------------^
|
|
|
|
|
|
2024-03-26 11:28:50 +00:00
|
|
|
= Function "latest": Expected function argument of type integer
|
2023-03-25 03:14:26 +00:00
|
|
|
"###);
|
|
|
|
|
2022-11-01 14:18:33 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "file()"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Function "file": Expected at least 1 argument
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:6
|
2022-11-01 14:18:33 +00:00
|
|
|
|
|
|
|
|
1 | file()
|
|
|
|
| ^
|
|
|
|
|
|
2024-03-26 11:28:50 +00:00
|
|
|
= Function "file": Expected at least 1 argument
|
2022-11-01 14:18:33 +00:00
|
|
|
"###);
|
|
|
|
|
2024-04-05 13:04:32 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "file(a, not@a-string)"]);
|
2022-11-01 14:13:18 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-04-05 13:04:32 +00:00
|
|
|
Error: Failed to parse revset: Function "file": Expected function argument of file pattern
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:9
|
2022-11-01 14:13:18 +00:00
|
|
|
|
|
2024-04-05 13:04:32 +00:00
|
|
|
1 | file(a, not@a-string)
|
2022-11-01 14:13:18 +00:00
|
|
|
| ^----------^
|
|
|
|
|
|
2024-04-05 13:04:32 +00:00
|
|
|
= Function "file": Expected function argument of file pattern
|
|
|
|
"###);
|
|
|
|
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", r#"file(foo:"bar")"#]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Failed to parse revset: Function "file": Invalid file pattern
|
|
|
|
Caused by:
|
|
|
|
1: --> 1:6
|
|
|
|
|
|
|
|
|
1 | file(foo:"bar")
|
|
|
|
| ^-------^
|
|
|
|
|
|
|
|
|
= Function "file": Invalid file pattern
|
|
|
|
2: Invalid file pattern kind "foo:"
|
2022-11-01 14:13:18 +00:00
|
|
|
"###);
|
|
|
|
|
2022-11-01 13:57:31 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", r#"file(a, "../out")"#]);
|
2023-11-20 07:59:54 +00:00
|
|
|
insta::assert_snapshot!(stderr.replace('\\', "/"), @r###"
|
2024-03-27 12:36:40 +00:00
|
|
|
Error: Failed to parse revset: Function "file": Invalid file pattern
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by:
|
|
|
|
1: --> 1:9
|
2022-11-01 13:57:31 +00:00
|
|
|
|
|
|
|
|
1 | file(a, "../out")
|
|
|
|
| ^------^
|
|
|
|
|
|
2024-03-27 12:36:40 +00:00
|
|
|
= Function "file": Invalid file pattern
|
2024-03-25 15:54:39 +00:00
|
|
|
2: Path "../out" is not in the repo "."
|
|
|
|
3: Invalid component ".." in repo-relative path "../out"
|
2022-11-01 13:57:31 +00:00
|
|
|
"###);
|
2022-11-01 14:04:54 +00:00
|
|
|
|
2023-08-16 09:41:21 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "branches(bad:pattern)"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-29 04:07:31 +00:00
|
|
|
Error: Failed to parse revset: Function "branches": Invalid string pattern
|
|
|
|
Caused by:
|
|
|
|
1: --> 1:10
|
2023-08-16 09:41:21 +00:00
|
|
|
|
|
|
|
|
1 | branches(bad:pattern)
|
|
|
|
| ^---------^
|
|
|
|
|
|
2024-03-29 04:07:31 +00:00
|
|
|
= Function "branches": Invalid string pattern
|
2024-03-06 08:49:15 +00:00
|
|
|
2: Invalid string pattern kind "bad:"
|
|
|
|
Hint: Try prefixing with one of `exact:`, `glob:` or `substring:`
|
2023-08-16 09:41:21 +00:00
|
|
|
"###);
|
|
|
|
|
2023-09-03 03:47:23 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "root()::whatever()"]);
|
2022-11-01 14:04:54 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Function "whatever" doesn't exist
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:9
|
2022-11-01 14:04:54 +00:00
|
|
|
|
|
2023-09-03 03:47:23 +00:00
|
|
|
1 | root()::whatever()
|
|
|
|
| ^------^
|
2022-11-01 14:04:54 +00:00
|
|
|
|
|
2024-03-26 11:28:50 +00:00
|
|
|
= Function "whatever" doesn't exist
|
2022-11-01 14:04:54 +00:00
|
|
|
"###);
|
2023-02-08 09:55:15 +00:00
|
|
|
|
|
|
|
let stderr = test_env.jj_cmd_failure(
|
|
|
|
&repo_path,
|
|
|
|
&["log", "-r", "remote_branches(a, b, remote=c)"],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Function "remote_branches": Got multiple values for keyword "remote"
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:23
|
2023-02-08 09:55:15 +00:00
|
|
|
|
|
|
|
|
1 | remote_branches(a, b, remote=c)
|
|
|
|
| ^------^
|
|
|
|
|
|
2024-03-26 11:28:50 +00:00
|
|
|
= Function "remote_branches": Got multiple values for keyword "remote"
|
2023-02-08 09:55:15 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
let stderr =
|
|
|
|
test_env.jj_cmd_failure(&repo_path, &["log", "-r", "remote_branches(remote=a, b)"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Function "remote_branches": Positional argument follows keyword argument
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:27
|
2023-02-08 09:55:15 +00:00
|
|
|
|
|
|
|
|
1 | remote_branches(remote=a, b)
|
|
|
|
| ^
|
|
|
|
|
|
2024-03-26 11:28:50 +00:00
|
|
|
= Function "remote_branches": Positional argument follows keyword argument
|
2023-02-08 09:55:15 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "remote_branches(=foo)"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Syntax error
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:17
|
2023-02-08 09:55:15 +00:00
|
|
|
|
|
|
|
|
1 | remote_branches(=foo)
|
|
|
|
| ^---
|
|
|
|
|
|
2023-09-07 01:11:48 +00:00
|
|
|
= expected <identifier> or <expression>
|
2023-02-08 09:55:15 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "remote_branches(remote=)"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Syntax error
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:24
|
2023-02-08 09:55:15 +00:00
|
|
|
|
|
|
|
|
1 | remote_branches(remote=)
|
|
|
|
| ^---
|
|
|
|
|
|
2023-09-07 01:11:48 +00:00
|
|
|
= expected <expression>
|
2023-02-08 09:55:15 +00:00
|
|
|
"###);
|
2022-11-01 13:57:31 +00:00
|
|
|
}
|
2022-11-25 10:27:13 +00:00
|
|
|
|
2023-03-23 09:03:01 +00:00
|
|
|
#[test]
|
|
|
|
fn test_function_name_hint() {
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2023-03-23 09:03:01 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
let evaluate_err = |expr| test_env.jj_cmd_failure(&repo_path, &["log", "-r", expr]);
|
|
|
|
|
|
|
|
test_env.add_config(
|
|
|
|
r###"
|
|
|
|
[revset-aliases]
|
|
|
|
'branches(x)' = 'x' # override builtin function
|
|
|
|
'my_author(x)' = 'author(x)' # similar name to builtin function
|
|
|
|
'author_sym' = 'x' # not a function alias
|
2024-02-26 13:46:43 +00:00
|
|
|
'my_branches' = 'branch()' # typo in alias
|
2023-03-23 09:03:01 +00:00
|
|
|
"###,
|
|
|
|
);
|
|
|
|
|
|
|
|
// The suggestion "branches" shouldn't be duplicated
|
|
|
|
insta::assert_snapshot!(evaluate_err("branch()"), @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Function "branch" doesn't exist
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:1
|
2023-03-23 09:03:01 +00:00
|
|
|
|
|
|
|
|
1 | branch()
|
|
|
|
| ^----^
|
|
|
|
|
|
2024-03-26 11:28:50 +00:00
|
|
|
= Function "branch" doesn't exist
|
2023-03-23 09:03:01 +00:00
|
|
|
Hint: Did you mean "branches"?
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// Both builtin function and function alias should be suggested
|
|
|
|
insta::assert_snapshot!(evaluate_err("author_()"), @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Function "author_" doesn't exist
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:1
|
2023-03-23 09:03:01 +00:00
|
|
|
|
|
|
|
|
1 | author_()
|
|
|
|
| ^-----^
|
|
|
|
|
|
2024-03-26 11:28:50 +00:00
|
|
|
= Function "author_" doesn't exist
|
2023-03-23 09:03:01 +00:00
|
|
|
Hint: Did you mean "author", "my_author"?
|
|
|
|
"###);
|
2024-02-26 13:46:43 +00:00
|
|
|
|
|
|
|
insta::assert_snapshot!(evaluate_err("my_branches"), @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Alias "my_branches" cannot be expanded
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by:
|
|
|
|
1: --> 1:1
|
2024-02-26 13:46:43 +00:00
|
|
|
|
|
|
|
|
1 | my_branches
|
|
|
|
| ^---------^
|
|
|
|
|
|
|
|
|
= Alias "my_branches" cannot be expanded
|
2024-03-25 15:54:39 +00:00
|
|
|
2: --> 1:1
|
2024-02-26 13:46:43 +00:00
|
|
|
|
|
|
|
|
1 | branch()
|
|
|
|
| ^----^
|
|
|
|
|
|
2024-03-26 11:28:50 +00:00
|
|
|
= Function "branch" doesn't exist
|
2024-02-26 13:46:43 +00:00
|
|
|
Hint: Did you mean "branches"?
|
|
|
|
"###);
|
2023-03-23 09:03:01 +00:00
|
|
|
}
|
|
|
|
|
2022-11-25 10:27:13 +00:00
|
|
|
#[test]
|
|
|
|
fn test_alias() {
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2022-11-25 10:27:13 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
test_env.add_config(
|
2023-01-26 19:26:18 +00:00
|
|
|
r###"
|
2022-11-25 10:27:13 +00:00
|
|
|
[revset-aliases]
|
2023-09-03 03:47:23 +00:00
|
|
|
'my-root' = 'root()'
|
2022-11-25 10:27:13 +00:00
|
|
|
'syntax-error' = 'whatever &'
|
|
|
|
'recurse' = 'recurse1'
|
2022-11-26 11:41:55 +00:00
|
|
|
'recurse1' = 'recurse2()'
|
|
|
|
'recurse2()' = 'recurse'
|
|
|
|
'identity(x)' = 'x'
|
|
|
|
'my_author(x)' = 'author(x)'
|
2022-11-25 10:27:13 +00:00
|
|
|
"###,
|
|
|
|
);
|
|
|
|
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "my-root"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-09-03 03:47:23 +00:00
|
|
|
◉ zzzzzzzz root() 00000000
|
2022-11-25 10:27:13 +00:00
|
|
|
"###);
|
|
|
|
|
2022-11-26 11:41:55 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "identity(my-root)"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-09-03 03:47:23 +00:00
|
|
|
◉ zzzzzzzz root() 00000000
|
2022-11-26 11:41:55 +00:00
|
|
|
"###);
|
|
|
|
|
2023-09-03 03:47:23 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "root() & syntax-error"]);
|
2022-11-25 10:27:13 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Alias "syntax-error" cannot be expanded
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by:
|
|
|
|
1: --> 1:10
|
2022-11-25 10:27:13 +00:00
|
|
|
|
|
2023-09-03 03:47:23 +00:00
|
|
|
1 | root() & syntax-error
|
|
|
|
| ^----------^
|
2022-11-25 10:27:13 +00:00
|
|
|
|
|
|
|
|
= Alias "syntax-error" cannot be expanded
|
2024-03-25 15:54:39 +00:00
|
|
|
2: --> 1:11
|
2022-11-25 10:27:13 +00:00
|
|
|
|
|
|
|
|
1 | whatever &
|
|
|
|
| ^---
|
|
|
|
|
|
2023-09-07 01:11:48 +00:00
|
|
|
= expected `::`, `..`, `~`, or <primary>
|
2022-11-25 10:27:13 +00:00
|
|
|
"###);
|
|
|
|
|
2022-11-26 11:41:55 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "identity()"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Function "identity": Expected 1 arguments
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by: --> 1:10
|
2022-11-26 11:41:55 +00:00
|
|
|
|
|
|
|
|
1 | identity()
|
|
|
|
| ^
|
|
|
|
|
|
2024-03-26 11:28:50 +00:00
|
|
|
= Function "identity": Expected 1 arguments
|
2022-11-26 11:41:55 +00:00
|
|
|
"###);
|
|
|
|
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "my_author(none())"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Alias "my_author()" cannot be expanded
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by:
|
|
|
|
1: --> 1:1
|
2022-11-26 11:41:55 +00:00
|
|
|
|
|
|
|
|
1 | my_author(none())
|
2022-11-27 11:45:35 +00:00
|
|
|
| ^---------------^
|
2022-11-26 11:41:55 +00:00
|
|
|
|
|
|
|
|
= Alias "my_author()" cannot be expanded
|
2024-03-25 15:54:39 +00:00
|
|
|
2: --> 1:8
|
2022-11-26 11:41:55 +00:00
|
|
|
|
|
|
|
|
1 | author(x)
|
|
|
|
| ^
|
|
|
|
|
|
2024-03-26 11:28:50 +00:00
|
|
|
= Function "author": Expected function argument of string pattern
|
2022-11-26 11:41:55 +00:00
|
|
|
"###);
|
|
|
|
|
2023-09-03 03:47:23 +00:00
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "root() & recurse"]);
|
2022-11-25 10:27:13 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-26 11:28:50 +00:00
|
|
|
Error: Failed to parse revset: Alias "recurse" cannot be expanded
|
2024-03-25 15:54:39 +00:00
|
|
|
Caused by:
|
|
|
|
1: --> 1:10
|
2022-11-25 10:27:13 +00:00
|
|
|
|
|
2023-09-03 03:47:23 +00:00
|
|
|
1 | root() & recurse
|
|
|
|
| ^-----^
|
2022-11-25 10:27:13 +00:00
|
|
|
|
|
|
|
|
= Alias "recurse" cannot be expanded
|
2024-03-25 15:54:39 +00:00
|
|
|
2: --> 1:1
|
2022-11-25 10:27:13 +00:00
|
|
|
|
|
|
|
|
1 | recurse1
|
|
|
|
| ^------^
|
|
|
|
|
|
|
|
|
= Alias "recurse1" cannot be expanded
|
2024-03-25 15:54:39 +00:00
|
|
|
3: --> 1:1
|
2022-11-25 10:27:13 +00:00
|
|
|
|
|
2022-11-26 11:41:55 +00:00
|
|
|
1 | recurse2()
|
2022-11-27 11:45:35 +00:00
|
|
|
| ^--------^
|
2022-11-26 11:41:55 +00:00
|
|
|
|
|
|
|
|
= Alias "recurse2()" cannot be expanded
|
2024-03-25 15:54:39 +00:00
|
|
|
4: --> 1:1
|
2022-11-26 11:41:55 +00:00
|
|
|
|
|
2022-11-25 10:27:13 +00:00
|
|
|
1 | recurse
|
|
|
|
| ^-----^
|
|
|
|
|
|
|
|
|
= Alias "recurse" expanded recursively
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2023-05-23 03:45:11 +00:00
|
|
|
#[test]
|
|
|
|
fn test_alias_override() {
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2023-05-23 03:45:11 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
test_env.add_config(
|
|
|
|
r###"
|
|
|
|
[revset-aliases]
|
|
|
|
'f(x)' = 'user'
|
|
|
|
"###,
|
|
|
|
);
|
|
|
|
|
|
|
|
// 'f(x)' should be overridden by --config-toml 'f(a)'. If aliases were sorted
|
|
|
|
// purely by name, 'f(a)' would come first.
|
|
|
|
let stderr = test_env.jj_cmd_failure(
|
|
|
|
&repo_path,
|
|
|
|
&[
|
|
|
|
"log",
|
|
|
|
"-r",
|
|
|
|
"f(_)",
|
|
|
|
"--config-toml",
|
|
|
|
"revset-aliases.'f(a)' = 'arg'",
|
|
|
|
],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Revision "arg" doesn't exist
|
|
|
|
"###);
|
|
|
|
}
|
|
|
|
|
2022-11-25 10:27:13 +00:00
|
|
|
#[test]
|
|
|
|
fn test_bad_alias_decl() {
|
|
|
|
let test_env = TestEnvironment::default();
|
2023-10-10 11:59:18 +00:00
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
|
2022-11-25 10:27:13 +00:00
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
test_env.add_config(
|
2023-08-15 03:18:52 +00:00
|
|
|
r#"
|
2022-11-25 10:27:13 +00:00
|
|
|
[revset-aliases]
|
2023-09-03 03:47:23 +00:00
|
|
|
'my-root' = 'root()'
|
|
|
|
'"bad"' = 'root()'
|
|
|
|
'badfn(a, a)' = 'root()'
|
2023-08-15 03:18:52 +00:00
|
|
|
"#,
|
2022-11-25 10:27:13 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Invalid declaration should be warned and ignored.
|
2023-07-03 10:04:31 +00:00
|
|
|
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-r", "my-root"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
2023-09-03 03:47:23 +00:00
|
|
|
◉ zzzzzzzz root() 00000000
|
2022-11-25 10:27:13 +00:00
|
|
|
"###);
|
2023-07-03 10:04:31 +00:00
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
2024-03-24 06:47:47 +00:00
|
|
|
Warning: Failed to load "revset-aliases."bad"": --> 1:1
|
2022-11-25 10:27:13 +00:00
|
|
|
|
|
|
|
|
1 | "bad"
|
|
|
|
| ^---
|
|
|
|
|
|
2023-09-07 01:11:48 +00:00
|
|
|
= expected <identifier> or <function_name>
|
2024-03-24 06:47:47 +00:00
|
|
|
Warning: Failed to load "revset-aliases.badfn(a, a)": --> 1:7
|
2022-11-26 11:41:55 +00:00
|
|
|
|
|
|
|
|
1 | badfn(a, a)
|
|
|
|
| ^--^
|
|
|
|
|
|
|
|
|
= Redefinition of function parameter
|
2022-11-25 10:27:13 +00:00
|
|
|
"###);
|
|
|
|
}
|
2024-05-10 00:25:33 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_all_modifier() {
|
|
|
|
let test_env = TestEnvironment::default();
|
|
|
|
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
|
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
|
|
|
|
// Command that accepts single revision by default
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["new", "all()"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Revset "all()" resolved to more than one revision
|
|
|
|
Hint: The revset "all()" resolved to these revisions:
|
|
|
|
qpvuntsm 230dd059 (empty) (no description set)
|
|
|
|
zzzzzzzz 00000000 (empty) (no description set)
|
|
|
|
Hint: Prefix the expression with 'all:' to allow any number of revisions (i.e. 'all:all()').
|
|
|
|
"###);
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["new", "all:all()"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: The Git backend does not support creating merge commits with the root commit as one of the parents.
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// Command that accepts multiple revisions by default
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-rall:all()"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
@ qpvuntsm test.user@example.com 2001-02-03 08:05:07 230dd059
|
|
|
|
│ (empty) (no description set)
|
|
|
|
◉ zzzzzzzz root() 00000000
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// Command that accepts only single revision
|
|
|
|
let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["branch", "create", "-rall:@", "x"]);
|
|
|
|
insta::assert_snapshot!(stderr, @"");
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["branch", "set", "-rall:all()", "x"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Revset "all:all()" resolved to more than one revision
|
|
|
|
Hint: The revset "all:all()" resolved to these revisions:
|
|
|
|
qpvuntsm 230dd059 x | (empty) (no description set)
|
|
|
|
zzzzzzzz 00000000 (empty) (no description set)
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// Template expression that accepts multiple revisions by default
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-Tself.contained_in('all:all()')"]);
|
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
@ true
|
|
|
|
◉ true
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// Typo
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["new", "ale:x"]);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Failed to parse revset: Modifier "ale" doesn't exist
|
|
|
|
Caused by: --> 1:1
|
|
|
|
|
|
|
|
|
1 | ale:x
|
|
|
|
| ^-^
|
|
|
|
|
|
|
|
|
= Modifier "ale" doesn't exist
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// Modifier shouldn't be allowed in aliases (This restriction might be
|
|
|
|
// lifted later. "all:" in alias could be allowed if it is expanded to the
|
|
|
|
// top-level expression.)
|
|
|
|
let stderr = test_env.jj_cmd_failure(
|
|
|
|
&repo_path,
|
|
|
|
&["new", "x", "--config-toml=revset-aliases.x='all:@'"],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Error: Failed to parse revset: Alias "x" cannot be expanded
|
|
|
|
Caused by:
|
|
|
|
1: --> 1:1
|
|
|
|
|
|
|
|
|
1 | x
|
|
|
|
| ^
|
|
|
|
|
|
|
|
|
= Alias "x" cannot be expanded
|
|
|
|
2: --> 1:4
|
|
|
|
|
|
|
|
|
1 | all:@
|
|
|
|
| ^
|
|
|
|
|
|
|
|
|
= ':' is not an infix operator
|
|
|
|
Hint: Did you mean '::' for DAG range?
|
|
|
|
"###);
|
|
|
|
|
|
|
|
// immutable_heads() alias may be parsed as a top-level expression, but
|
|
|
|
// still, modifier shouldn't be allowed there.
|
|
|
|
let stderr = test_env.jj_cmd_failure(
|
|
|
|
&repo_path,
|
|
|
|
&[
|
|
|
|
"new",
|
|
|
|
"--config-toml=revset-aliases.'immutable_heads()'='all:@'",
|
|
|
|
"--config-toml=revsets.short-prefixes='none()'",
|
|
|
|
],
|
|
|
|
);
|
|
|
|
insta::assert_snapshot!(stderr, @r###"
|
|
|
|
Config error: Invalid `revset-aliases.immutable_heads()`
|
|
|
|
Caused by: --> 1:4
|
|
|
|
|
|
|
|
|
1 | all:@
|
|
|
|
| ^
|
|
|
|
|
|
|
|
|
= ':' is not an infix operator
|
|
|
|
For help, see https://github.com/martinvonz/jj/blob/main/docs/config.md.
|
|
|
|
"###);
|
|
|
|
}
|