just playing with tangled
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cli `fix`: add `revsets.fix` config for default revset to be fixed

+77 -10
+3
CHANGELOG.md
··· 22 22 23 23 * Show paths to config files when configuration errors occur 24 24 25 + * `jj fix` now supports configuring the default revset for `-s` using the 26 + `revsets.fix` config. 27 + 25 28 ### Fixed bugs 26 29 27 30 ## [0.18.0] - 2024-06-05
+12 -9
cli/src/commands/fix.rs
··· 65 65 #[derive(clap::Args, Clone, Debug)] 66 66 #[command(verbatim_doc_comment)] 67 67 pub(crate) struct FixArgs { 68 - /// Fix files in the specified revision(s) and their descendants 68 + /// Fix files in the specified revision(s) and their descendants. If no 69 + /// revisions are specified, this defaults to the `revsets.fix` setting, or 70 + /// `@` if it is not set. 69 71 #[arg(long, short)] 70 72 source: Vec<RevisionArg>, 71 73 /// Fix only these paths ··· 80 82 args: &FixArgs, 81 83 ) -> Result<(), CommandError> { 82 84 let mut workspace_command = command.workspace_helper(ui)?; 83 - let root_commits: Vec<CommitId> = workspace_command 84 - .parse_union_revsets(if args.source.is_empty() { 85 - &[RevisionArg::AT] 86 - } else { 87 - &args.source 88 - })? 89 - .evaluate_to_commit_ids()? 90 - .collect(); 85 + let root_commits: Vec<CommitId> = if args.source.is_empty() { 86 + workspace_command.parse_revset(&RevisionArg::from( 87 + command.settings().config().get_string("revsets.fix")?, 88 + ))? 89 + } else { 90 + workspace_command.parse_union_revsets(&args.source)? 91 + } 92 + .evaluate_to_commit_ids()? 93 + .collect(); 91 94 workspace_command.check_rewritable(root_commits.iter())?; 92 95 let matcher = workspace_command 93 96 .parse_file_patterns(&args.paths)?
+5
cli/src/config-schema.json
··· 346 346 "type": "object", 347 347 "description": "Revset expressions used by various commands", 348 348 "properties": { 349 + "fix": { 350 + "type": "string", 351 + "description": "Default set of revisions to fix when no explicit revset is given for jj fix", 352 + "default": "@" 353 + }, 349 354 "log": { 350 355 "type": "string", 351 356 "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
··· 2 2 # adding/updating any of these aliases 3 3 4 4 [revsets] 5 + fix = "@" 5 6 log = "@ | ancestors(immutable_heads().., 2) | trunk()" 6 7 7 8 [revset-aliases]
+1 -1
cli/tests/cli-reference@.md.snap
··· 798 798 799 799 ###### **Options:** 800 800 801 - * `-s`, `--source <SOURCE>` — Fix files in the specified revision(s) and their descendants 801 + * `-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 802 802 803 803 804 804
+55
cli/tests/test_fix_command.rs
··· 140 140 } 141 141 142 142 #[test] 143 + fn test_default_revset() { 144 + let (test_env, repo_path) = init_with_fake_formatter(&["--uppercase"]); 145 + std::fs::write(repo_path.join("file"), "foo").unwrap(); 146 + test_env.jj_cmd_ok(&repo_path, &["branch", "create", "foo"]); 147 + test_env.jj_cmd_ok(&repo_path, &["new"]); 148 + std::fs::write(repo_path.join("file"), "bar").unwrap(); 149 + test_env.jj_cmd_ok(&repo_path, &["branch", "create", "bar"]); 150 + test_env.jj_cmd_ok(&repo_path, &["new", "foo"]); 151 + std::fs::write(repo_path.join("file"), "baz").unwrap(); 152 + test_env.jj_cmd_ok(&repo_path, &["branch", "create", "baz"]); 153 + 154 + // With no args and no revset configuration, we fix `@`. 155 + let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["fix"]); 156 + insta::assert_snapshot!(stdout, @""); 157 + insta::assert_snapshot!(stderr, @r###" 158 + Fixed 1 commits of 1 checked. 159 + Working copy now at: mzvwutvl 5205c5f1 baz | (no description set) 160 + Parent commit : qpvuntsm 34af74d0 foo | (no description set) 161 + Added 0 files, modified 1 files, removed 0 files 162 + "###); 163 + let content = test_env.jj_cmd_success(&repo_path, &["print", "file", "-r", "foo"]); 164 + insta::assert_snapshot!(content, @"foo"); 165 + let content = test_env.jj_cmd_success(&repo_path, &["print", "file", "-r", "bar"]); 166 + insta::assert_snapshot!(content, @"bar"); 167 + let content = test_env.jj_cmd_success(&repo_path, &["print", "file", "-r", "baz"]); 168 + insta::assert_snapshot!(content, @"BAZ"); 169 + } 170 + 171 + #[test] 172 + fn test_custom_default_revset() { 173 + let (test_env, repo_path) = init_with_fake_formatter(&["--uppercase"]); 174 + 175 + std::fs::write(repo_path.join("file"), "foo").unwrap(); 176 + test_env.jj_cmd_ok(&repo_path, &["branch", "create", "foo"]); 177 + test_env.jj_cmd_ok(&repo_path, &["new"]); 178 + std::fs::write(repo_path.join("file"), "bar").unwrap(); 179 + test_env.jj_cmd_ok(&repo_path, &["branch", "create", "bar"]); 180 + 181 + // Check out a different commit so that the schema default `@` would behave 182 + // differently from our customized default. 183 + test_env.jj_cmd_ok(&repo_path, &["new", "-r", "foo"]); 184 + test_env.add_config(r#"revsets.fix = "bar""#); 185 + 186 + let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["fix"]); 187 + insta::assert_snapshot!(stdout, @""); 188 + insta::assert_snapshot!(stderr, @r###" 189 + Fixed 1 commits of 1 checked. 190 + "###); 191 + let content = test_env.jj_cmd_success(&repo_path, &["print", "file", "-r", "foo"]); 192 + insta::assert_snapshot!(content, @"foo"); 193 + let content = test_env.jj_cmd_success(&repo_path, &["print", "file", "-r", "bar"]); 194 + insta::assert_snapshot!(content, @"BAR"); 195 + } 196 + 197 + #[test] 143 198 fn test_fix_immutable_commit() { 144 199 let (test_env, repo_path) = init_with_fake_formatter(&["--uppercase"]); 145 200 std::fs::write(repo_path.join("file"), "immutable").unwrap();