From 3785304209edf29a8dd4868ef6b3ba49834ce7aa Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Sat, 15 Jun 2024 13:27:01 -0400 Subject: [PATCH] cli: create `jj file list` and deprecate `jj files` --- CHANGELOG.md | 2 ++ cli/src/commands/{files.rs => file/list.rs} | 23 ++++++++++++++++++--- cli/src/commands/file/mod.rs | 3 +++ cli/src/commands/mod.rs | 7 ++++--- cli/tests/cli-reference@.md.snap | 8 +++---- cli/tests/test_alias.rs | 6 ++++-- cli/tests/test_sparse_command.rs | 2 +- cli/tests/test_untrack_command.rs | 12 +++++------ cli/tests/test_working_copy.rs | 4 ++-- 9 files changed, 46 insertions(+), 21 deletions(-) rename cli/src/commands/{files.rs => file/list.rs} (75%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ba57676e4..cbd818cd13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * `jj file chmod` replaces `jj chmod`. +* `jj file list` (aka `jj file ls`) replaces `jj files`. + ### New features * Support background filesystem monitoring via watchman triggers enabled with diff --git a/cli/src/commands/files.rs b/cli/src/commands/file/list.rs similarity index 75% rename from cli/src/commands/files.rs rename to cli/src/commands/file/list.rs index 5b836795ae..03889c576f 100644 --- a/cli/src/commands/files.rs +++ b/cli/src/commands/file/list.rs @@ -22,7 +22,7 @@ use crate::ui::Ui; /// List files in a revision #[derive(clap::Args, Clone, Debug)] -pub(crate) struct FilesArgs { +pub(crate) struct ListArgs { /// The revision to list files in #[arg(long, short, default_value = "@")] revision: RevisionArg, @@ -32,10 +32,27 @@ pub(crate) struct FilesArgs { } #[instrument(skip_all)] -pub(crate) fn cmd_files( +pub(crate) fn deprecated_cmd_files( ui: &mut Ui, command: &CommandHelper, - args: &FilesArgs, + args: &ListArgs, +) -> Result<(), CommandError> { + writeln!( + ui.warning_default(), + "`jj files` is deprecated; use `jj file list` instead, which is equivalent" + )?; + writeln!( + ui.warning_default(), + "`jj files` will be removed in a future version, and this will be a hard error" + )?; + cmd_list(ui, command, args) +} + +#[instrument(skip_all)] +pub(crate) fn cmd_list( + ui: &mut Ui, + command: &CommandHelper, + args: &ListArgs, ) -> Result<(), CommandError> { let workspace_command = command.workspace_helper(ui)?; let commit = workspace_command.resolve_single_rev(&args.revision)?; diff --git a/cli/src/commands/file/mod.rs b/cli/src/commands/file/mod.rs index db55145afd..c2d572f992 100644 --- a/cli/src/commands/file/mod.rs +++ b/cli/src/commands/file/mod.rs @@ -13,6 +13,7 @@ // limitations under the License. pub mod chmod; +pub mod list; pub mod print; use crate::cli_util::CommandHelper; @@ -24,6 +25,7 @@ use crate::ui::Ui; pub enum FileCommand { Print(print::PrintArgs), Chmod(chmod::ChmodArgs), + List(list::ListArgs), } pub fn cmd_file( @@ -34,5 +36,6 @@ pub fn cmd_file( match subcommand { FileCommand::Print(sub_args) => print::cmd_print(ui, command, sub_args), FileCommand::Chmod(sub_args) => chmod::cmd_chmod(ui, command, sub_args), + FileCommand::List(sub_args) => list::cmd_list(ui, command, sub_args), } } diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs index 470a240c0a..9a2f9f3b7e 100644 --- a/cli/src/commands/mod.rs +++ b/cli/src/commands/mod.rs @@ -27,7 +27,6 @@ mod diffedit; mod duplicate; mod edit; mod file; -mod files; mod fix; mod git; mod init; @@ -94,7 +93,9 @@ enum Command { Edit(edit::EditArgs), #[command(subcommand)] File(file::FileCommand), - Files(files::FilesArgs), + /// List files in a revision (DEPRECATED use `jj file list`) + #[command(hide = true)] + Files(file::list::ListArgs), Fix(fix::FixArgs), #[command(subcommand)] Git(git::GitCommand), @@ -174,8 +175,8 @@ pub fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), Co Command::Checkout(sub_args) => checkout::cmd_checkout(ui, command_helper, sub_args), Command::Untrack(sub_args) => untrack::cmd_untrack(ui, command_helper, sub_args), Command::File(sub_args) => file::cmd_file(ui, command_helper, sub_args), - Command::Files(sub_args) => files::cmd_files(ui, command_helper, sub_args), Command::Cat(sub_args) => file::print::deprecated_cmd_cat(ui, command_helper, sub_args), + Command::Files(sub_args) => file::list::deprecated_cmd_files(ui, command_helper, sub_args), Command::Diff(sub_args) => diff::cmd_diff(ui, command_helper, sub_args), Command::Show(sub_args) => show::cmd_show(ui, command_helper, sub_args), Command::Status(sub_args) => status::cmd_status(ui, command_helper, sub_args), diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index 9e3ac8faca..7e5711f493 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -37,7 +37,7 @@ This document contains the help content for the `jj` command-line program. * [`jj file`↴](#jj-file) * [`jj file print`↴](#jj-file-print) * [`jj file chmod`↴](#jj-file-chmod) -* [`jj files`↴](#jj-files) +* [`jj file list`↴](#jj-file-list) * [`jj fix`↴](#jj-fix) * [`jj git`↴](#jj-git) * [`jj git remote`↴](#jj-git-remote) @@ -117,7 +117,6 @@ To get started, see the tutorial at https://github.com/martinvonz/jj/blob/main/d * `duplicate` — Create a new change with the same content as an existing one * `edit` — Sets the specified revision as the working-copy revision * `file` — File operations -* `files` — List files in a revision * `fix` — Update files with formatting fixes or other changes * `git` — Commands for working with Git remotes and the underlying Git repo * `init` — Create a new repo in the given directory @@ -655,6 +654,7 @@ File operations * `print` — Print contents of files in a revision * `chmod` — Sets or removes the executable bit for paths in the repo +* `list` — List files in a revision @@ -706,11 +706,11 @@ Unlike the POSIX `chmod`, `jj chmod` also works on Windows, on conflicted files, -## `jj files` +## `jj file list` List files in a revision -**Usage:** `jj files [OPTIONS] [PATHS]...` +**Usage:** `jj file list [OPTIONS] [PATHS]...` ###### **Arguments:** diff --git a/cli/tests/test_alias.rs b/cli/tests/test_alias.rs index b542a81942..e24b7d1063 100644 --- a/cli/tests/test_alias.rs +++ b/cli/tests/test_alias.rs @@ -316,8 +316,10 @@ fn test_alias_in_repo_config() { "###); // No warning if the expanded command is identical. - let (stdout, stderr) = - test_env.jj_cmd_ok(&repo1_path, &["files", "-R", repo2_path.to_str().unwrap()]); + let (stdout, stderr) = test_env.jj_cmd_ok( + &repo1_path, + &["file", "list", "-R", repo2_path.to_str().unwrap()], + ); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @""); diff --git a/cli/tests/test_sparse_command.rs b/cli/tests/test_sparse_command.rs index 0ad3f0dcdb..b01e791342 100644 --- a/cli/tests/test_sparse_command.rs +++ b/cli/tests/test_sparse_command.rs @@ -49,7 +49,7 @@ fn test_sparse_manage_patterns() { assert!(!repo_path.join("file2").exists()); assert!(!repo_path.join("file3").exists()); // But they're still in the commit - let stdout = test_env.jj_cmd_success(&repo_path, &["files"]); + let stdout = test_env.jj_cmd_success(&repo_path, &["file", "list"]); insta::assert_snapshot!(stdout, @r###" file1 file2 diff --git a/cli/tests/test_untrack_command.rs b/cli/tests/test_untrack_command.rs index 78804b59cc..53f08edc23 100644 --- a/cli/tests/test_untrack_command.rs +++ b/cli/tests/test_untrack_command.rs @@ -35,7 +35,7 @@ fn test_untrack() { // patterns test_env.jj_cmd_ok(&repo_path, &["st"]); std::fs::write(repo_path.join(".gitignore"), "*.bak\n").unwrap(); - let files_before = test_env.jj_cmd_success(&repo_path, &["files"]); + let files_before = test_env.jj_cmd_success(&repo_path, &["file", "list"]); // Errors out when not run at the head operation let stderr = test_env.jj_cmd_failure(&repo_path, &["untrack", "file1", "--at-op", "@-"]); @@ -60,7 +60,7 @@ fn test_untrack() { Hint: Files that are not ignored will be added back by the next command. Make sure they're ignored, then try again. "###); - let files_after = test_env.jj_cmd_success(&repo_path, &["files"]); + let files_after = test_env.jj_cmd_success(&repo_path, &["file", "list"]); // There should be no changes to the state when there was an error assert_eq!(files_after, files_before); @@ -69,7 +69,7 @@ fn test_untrack() { let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["untrack", "file1.bak"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @""); - let files_after = test_env.jj_cmd_success(&repo_path, &["files"]); + let files_after = test_env.jj_cmd_success(&repo_path, &["file", "list"]); // The file is no longer tracked assert!(!files_after.contains("file1.bak")); // Other files that match the ignore pattern are not untracked @@ -94,7 +94,7 @@ fn test_untrack() { let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["untrack", "target"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @""); - let files_after = test_env.jj_cmd_success(&repo_path, &["files"]); + let files_after = test_env.jj_cmd_success(&repo_path, &["file", "list"]); assert!(!files_after.contains("target")); } @@ -111,7 +111,7 @@ fn test_untrack_sparse() { // When untracking a file that's not included in the sparse working copy, it // doesn't need to be ignored (because it won't be automatically added // back). - let stdout = test_env.jj_cmd_success(&repo_path, &["files"]); + let stdout = test_env.jj_cmd_success(&repo_path, &["file", "list"]); insta::assert_snapshot!(stdout, @r###" file1 file2 @@ -120,7 +120,7 @@ fn test_untrack_sparse() { let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["untrack", "file2"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @""); - let stdout = test_env.jj_cmd_success(&repo_path, &["files"]); + let stdout = test_env.jj_cmd_success(&repo_path, &["file", "list"]); insta::assert_snapshot!(stdout, @r###" file1 "###); diff --git a/cli/tests/test_working_copy.rs b/cli/tests/test_working_copy.rs index 172d944bc9..55a859ca99 100644 --- a/cli/tests/test_working_copy.rs +++ b/cli/tests/test_working_copy.rs @@ -24,7 +24,7 @@ fn test_snapshot_large_file() { // in bytes test_env.add_config(r#"snapshot.max-new-file-size = 10"#); std::fs::write(repo_path.join("large"), "a lot of text").unwrap(); - let stderr = test_env.jj_cmd_failure(&repo_path, &["files"]); + let stderr = test_env.jj_cmd_failure(&repo_path, &["file", "list"]); insta::assert_snapshot!(stderr, @r###" Error: Failed to snapshot the working copy The file '$TEST_ENV/repo/large' is too large to be snapshotted: it is 3 bytes too large; the maximum size allowed is 10 bytes (10.0B). @@ -40,7 +40,7 @@ fn test_snapshot_large_file() { test_env.add_config(r#"snapshot.max-new-file-size = "10KB""#); let big_string = vec![0; 1024 * 11]; std::fs::write(repo_path.join("large"), big_string).unwrap(); - let stderr = test_env.jj_cmd_failure(&repo_path, &["files"]); + let stderr = test_env.jj_cmd_failure(&repo_path, &["file", "list"]); insta::assert_snapshot!(stderr, @r###" Error: Failed to snapshot the working copy The file '$TEST_ENV/repo/large' is too large to be snapshotted: it is 1024 bytes too large; the maximum size allowed is 10240 bytes (10.0KiB).