···22222323* Show paths to config files when configuration errors occur
24242525+* `jj fix` now supports configuring the default revset for `-s` using the
2626+ `revsets.fix` config.
2727+2528### Fixed bugs
26292730## [0.18.0] - 2024-06-05
+12-9
cli/src/commands/fix.rs
···6565#[derive(clap::Args, Clone, Debug)]
6666#[command(verbatim_doc_comment)]
6767pub(crate) struct FixArgs {
6868- /// Fix files in the specified revision(s) and their descendants
6868+ /// Fix files in the specified revision(s) and their descendants. If no
6969+ /// revisions are specified, this defaults to the `revsets.fix` setting, or
7070+ /// `@` if it is not set.
6971 #[arg(long, short)]
7072 source: Vec<RevisionArg>,
7173 /// Fix only these paths
···8082 args: &FixArgs,
8183) -> Result<(), CommandError> {
8284 let mut workspace_command = command.workspace_helper(ui)?;
8383- let root_commits: Vec<CommitId> = workspace_command
8484- .parse_union_revsets(if args.source.is_empty() {
8585- &[RevisionArg::AT]
8686- } else {
8787- &args.source
8888- })?
8989- .evaluate_to_commit_ids()?
9090- .collect();
8585+ let root_commits: Vec<CommitId> = if args.source.is_empty() {
8686+ workspace_command.parse_revset(&RevisionArg::from(
8787+ command.settings().config().get_string("revsets.fix")?,
8888+ ))?
8989+ } else {
9090+ workspace_command.parse_union_revsets(&args.source)?
9191+ }
9292+ .evaluate_to_commit_ids()?
9393+ .collect();
9194 workspace_command.check_rewritable(root_commits.iter())?;
9295 let matcher = workspace_command
9396 .parse_file_patterns(&args.paths)?
+5
cli/src/config-schema.json
···346346 "type": "object",
347347 "description": "Revset expressions used by various commands",
348348 "properties": {
349349+ "fix": {
350350+ "type": "string",
351351+ "description": "Default set of revisions to fix when no explicit revset is given for jj fix",
352352+ "default": "@"
353353+ },
349354 "log": {
350355 "type": "string",
351356 "description": "Default set of revisions to show when no explicit revset is given for jj log and similar commands",
+1
cli/src/config/revsets.toml
···22# adding/updating any of these aliases
3344[revsets]
55+fix = "@"
56log = "@ | ancestors(immutable_heads().., 2) | trunk()"
6778[revset-aliases]
+1-1
cli/tests/cli-reference@.md.snap
···798798799799###### **Options:**
800800801801-* `-s`, `--source <SOURCE>` — Fix files in the specified revision(s) and their descendants
801801+* `-s`, `--source <SOURCE>` — Fix files in the specified revision(s) and their descendants. If no revisions are specified, this defaults to the `revsets.fix` setting, or `@` if it is not set
802802803803804804
+55
cli/tests/test_fix_command.rs
···140140}
141141142142#[test]
143143+fn test_default_revset() {
144144+ let (test_env, repo_path) = init_with_fake_formatter(&["--uppercase"]);
145145+ std::fs::write(repo_path.join("file"), "foo").unwrap();
146146+ test_env.jj_cmd_ok(&repo_path, &["branch", "create", "foo"]);
147147+ test_env.jj_cmd_ok(&repo_path, &["new"]);
148148+ std::fs::write(repo_path.join("file"), "bar").unwrap();
149149+ test_env.jj_cmd_ok(&repo_path, &["branch", "create", "bar"]);
150150+ test_env.jj_cmd_ok(&repo_path, &["new", "foo"]);
151151+ std::fs::write(repo_path.join("file"), "baz").unwrap();
152152+ test_env.jj_cmd_ok(&repo_path, &["branch", "create", "baz"]);
153153+154154+ // With no args and no revset configuration, we fix `@`.
155155+ let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["fix"]);
156156+ insta::assert_snapshot!(stdout, @"");
157157+ insta::assert_snapshot!(stderr, @r###"
158158+ Fixed 1 commits of 1 checked.
159159+ Working copy now at: mzvwutvl 5205c5f1 baz | (no description set)
160160+ Parent commit : qpvuntsm 34af74d0 foo | (no description set)
161161+ Added 0 files, modified 1 files, removed 0 files
162162+ "###);
163163+ let content = test_env.jj_cmd_success(&repo_path, &["print", "file", "-r", "foo"]);
164164+ insta::assert_snapshot!(content, @"foo");
165165+ let content = test_env.jj_cmd_success(&repo_path, &["print", "file", "-r", "bar"]);
166166+ insta::assert_snapshot!(content, @"bar");
167167+ let content = test_env.jj_cmd_success(&repo_path, &["print", "file", "-r", "baz"]);
168168+ insta::assert_snapshot!(content, @"BAZ");
169169+}
170170+171171+#[test]
172172+fn test_custom_default_revset() {
173173+ let (test_env, repo_path) = init_with_fake_formatter(&["--uppercase"]);
174174+175175+ std::fs::write(repo_path.join("file"), "foo").unwrap();
176176+ test_env.jj_cmd_ok(&repo_path, &["branch", "create", "foo"]);
177177+ test_env.jj_cmd_ok(&repo_path, &["new"]);
178178+ std::fs::write(repo_path.join("file"), "bar").unwrap();
179179+ test_env.jj_cmd_ok(&repo_path, &["branch", "create", "bar"]);
180180+181181+ // Check out a different commit so that the schema default `@` would behave
182182+ // differently from our customized default.
183183+ test_env.jj_cmd_ok(&repo_path, &["new", "-r", "foo"]);
184184+ test_env.add_config(r#"revsets.fix = "bar""#);
185185+186186+ let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["fix"]);
187187+ insta::assert_snapshot!(stdout, @"");
188188+ insta::assert_snapshot!(stderr, @r###"
189189+ Fixed 1 commits of 1 checked.
190190+ "###);
191191+ let content = test_env.jj_cmd_success(&repo_path, &["print", "file", "-r", "foo"]);
192192+ insta::assert_snapshot!(content, @"foo");
193193+ let content = test_env.jj_cmd_success(&repo_path, &["print", "file", "-r", "bar"]);
194194+ insta::assert_snapshot!(content, @"BAR");
195195+}
196196+197197+#[test]
143198fn test_fix_immutable_commit() {
144199 let (test_env, repo_path) = init_with_fake_formatter(&["--uppercase"]);
145200 std::fs::write(repo_path.join("file"), "immutable").unwrap();