Skip to content

Commit

Permalink
feat: create jj file list and deprecate jj files
Browse files Browse the repository at this point in the history
  • Loading branch information
fowles committed Jun 17, 2024
1 parent 47bd6f4 commit 0cc8d41
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 20 additions & 3 deletions cli/src/commands/files.rs → cli/src/commands/file/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)?;
Expand Down
4 changes: 4 additions & 0 deletions cli/src/commands/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

pub mod chmod;
pub mod list;
pub mod print;

use crate::cli_util::CommandHelper;
Expand All @@ -24,6 +25,8 @@ use crate::ui::Ui;
pub enum FileCommand {
Print(print::PrintArgs),
Chmod(chmod::ChmodArgs),
#[command(visible_alias("ls"))]
List(list::ListArgs),
}

pub fn cmd_file(
Expand All @@ -34,5 +37,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),
}
}
6 changes: 3 additions & 3 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ mod diffedit;
mod duplicate;
mod edit;
mod file;
mod files;
mod fix;
mod git;
mod init;
Expand Down Expand Up @@ -94,7 +93,8 @@ enum Command {
Edit(edit::EditArgs),
#[command(subcommand)]
File(file::FileCommand),
Files(files::FilesArgs),
#[command(hide = true)]
Files(file::list::ListArgs),
Fix(fix::FixArgs),
#[command(subcommand)]
Git(git::GitCommand),
Expand Down Expand Up @@ -174,8 +174,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),
Expand Down
8 changes: 4 additions & 4 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:**
Expand Down
6 changes: 4 additions & 2 deletions cli/tests/test_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, @"");

Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_sparse_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions cli/tests/test_untrack_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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", "@-"]);
Expand All @@ -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);

Expand All @@ -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
Expand All @@ -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"));
}

Expand All @@ -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
Expand All @@ -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
"###);
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/test_working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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).
Expand Down

0 comments on commit 0cc8d41

Please sign in to comment.