Skip to content

Commit

Permalink
cli: redefine default log revset using immutable_heads()
Browse files Browse the repository at this point in the history
I think most users who change the set of immutable heads away from
`trunk() | tags()` are going to also want to change the default log
revset to include the newly mutable commit and to exclude the newly
immutable commits. So let's update the default log revset to use
`immutable_heads()` instead.

`test_templater` changed because we have overridden the set of
immutable commits there so `jj log` now includes the remote branch.
  • Loading branch information
martinvonz committed Oct 1, 2023
1 parent 8ec402f commit 58de7c2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 deletions.
3 changes: 2 additions & 1 deletion cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ struct StatusArgs {}
#[derive(clap::Args, Clone, Debug)]
struct LogArgs {
/// Which revisions to show. Defaults to the `revsets.log` setting, or
/// `@ | ancestors((remote_branches() | tags()).., 2)` if it is not set.
/// `@ | ancestors(immutable_heads().., 2) | heads(immutable_heads())` if
/// it is not set.
#[arg(long, short)]
revisions: Vec<RevisionArg>,
/// Show commits modifying the given paths
Expand Down
2 changes: 1 addition & 1 deletion cli/src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
"log": {
"type": "string",
"description": "Default set of revisions to show when no explicit revset is given for jj log and similar commands",
"default": "@ | ancestors((remote_branches() | tags()).., 2)"
"default": "@ | ancestors(immutable_heads().., 2) | heads(immutable_heads())"
},
"short-prefixes": {
"type": "string",
Expand Down
9 changes: 3 additions & 6 deletions cli/tests/test_branch_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,15 @@ fn test_branch_delete_glob() {

insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ bar-2 foo-1 foo-3 foo-4 6fbf398c2d59
~
◉ 000000000000
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["branch", "delete", "--glob", "foo-[1-3]"]);
insta::assert_snapshot!(stdout, @r###"
Deleted 2 branches.
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ bar-2 foo-1@origin foo-3@origin foo-4 6fbf398c2d59
~
◉ 000000000000
"###);

// We get an error if none of the globs match live branches. Unlike `jj branch
Expand All @@ -196,8 +194,7 @@ fn test_branch_delete_glob() {
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ bar-2 foo-1@origin foo-3@origin foo-4@origin 6fbf398c2d59
~
◉ 000000000000
"###);

// The deleted branches are still there
Expand Down
29 changes: 22 additions & 7 deletions cli/tests/test_immutable_commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,23 @@ fn test_rewrite_immutable_generic() {
Hint: Configure the set of immutable commits via `revset-aliases.immutable_heads()`.
"###);
// Error if we redefine immutable_heads() with an argument
// TODO: This error comes from the built-in definition of
// `revsets.short-prefixes`. That's not clear to the user.
test_env.add_config(r#"revset-aliases."immutable_heads(foo)" = "none()""#);
let stderr = test_env.jj_cmd_failure(&repo_path, &["edit", "root()"]);
insta::assert_snapshot!(stderr, @r###"
Config error: Invalid `revsets.short-prefixes`: --> 1:31
|
1 | @ | ancestors(immutable_heads().., 2) | heads(immutable_heads())
| ^
|
= Invalid arguments to revset function "immutable_heads": Expected 1 arguments
For help, see https://github.com/martinvonz/jj/blob/main/docs/config.md.
"###);
// ... even if we also update the built-in call sites
test_env.add_config(r#"revsets.short-prefixes = "immutable_heads(root())""#);
let stderr = test_env.jj_cmd_failure(&repo_path, &["edit", "root()"]);
insta::assert_snapshot!(stderr, @r###"
Error: The `revset-aliases.immutable_heads()` function must be declared without arguments.
"###);
}
Expand All @@ -82,19 +96,20 @@ fn test_rewrite_immutable_commands() {
test_env.jj_cmd_success(&repo_path, &["branch", "create", "main"]);
test_env.jj_cmd_success(&repo_path, &["new", "description(b)"]);
test_env.add_config(r#"revset-aliases."immutable_heads()" = "main""#);

// Log shows mutable commits and immutable heads by default
let stdout = test_env.jj_cmd_success(&repo_path, &["log"]);
insta::assert_snapshot!(stdout, @r###"
@ yqosqzyt [email protected] 2001-02-03 04:05:13.000 +07:00 3f89addf
│ (empty) (no description set)
│ ◉ mzvwutvl [email protected] 2001-02-03 04:05:11.000 +07:00 main d809c5d9 conflict
╭─┤ (empty) merge
◉ │ kkmpptxz [email protected] 2001-02-03 04:05:10.000 +07:00 c8d4c7ca
│ │ b
│ ◉ zsuskuln [email protected] 2001-02-03 04:05:11.000 +07:00 6e11f430
├─╯ c
◉ qpvuntsm [email protected] 2001-02-03 04:05:08.000 +07:00 46a8dc51
│ a
◉ zzzzzzzz root() 00000000
│ │
│ ~
◉ kkmpptxz [email protected] 2001-02-03 04:05:10.000 +07:00 c8d4c7ca
│ b
~
"###);

// abandon
Expand Down
4 changes: 3 additions & 1 deletion cli/tests/test_templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ fn test_templater_branches() {
let template = r#"commit_id.short() ++ " " ++ branches"#;
let output = test_env.jj_cmd_success(&workspace_root, &["log", "-T", template]);
insta::assert_snapshot!(output, @r###"
◉ b1bb3766d584 branch3??
◉ fed794e2ba44 branch3?? branch3@origin
│ ◉ b1bb3766d584 branch3??
├─╯
│ ◉ 21c33875443e branch1*
├─╯
│ @ a5b4d15489cc branch2* new-branch
Expand Down
4 changes: 3 additions & 1 deletion lib/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ impl UserSettings {
// For compatibility with old config files (<0.8.0)
self.config
.get_string("ui.default-revset")
.unwrap_or_else(|_| "@ | ancestors((remote_branches() | tags()).., 2)".to_string())
.unwrap_or_else(|_| {
"@ | ancestors(immutable_heads().., 2) | heads(immutable_heads())".to_string()
})
})
}

Expand Down

0 comments on commit 58de7c2

Please sign in to comment.