From 6b65f8abece95e5c1349c0b52b24813eb09993ea Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 25 Aug 2024 21:27:15 +0900 Subject: [PATCH] cli: move "untrack" to "file" subcommand I don't think "jj untrack" is frequently used, and I think it is a "file" command rather than "workspace". --- CHANGELOG.md | 2 ++ cli/src/commands/file/mod.rs | 3 ++ cli/src/commands/{ => file}/untrack.rs | 6 ++-- cli/src/commands/mod.rs | 10 ++++-- cli/tests/cli-reference@.md.snap | 32 +++++++++---------- cli/tests/runner.rs | 2 +- ...ommand.rs => test_file_untrack_command.rs} | 20 +++++++----- docs/tutorial.md | 2 +- docs/working-copy.md | 2 +- 9 files changed, 46 insertions(+), 33 deletions(-) rename cli/src/commands/{ => file}/untrack.rs (97%) rename cli/tests/{test_untrack_command.rs => test_file_untrack_command.rs} (85%) diff --git a/CHANGELOG.md b/CHANGELOG.md index e06922cdb..28c40cd37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Deprecations +* `jj untrack` has been renamed to `jj file untrack`. + ### New features * Add new boolean config knob, `ui.movement.edit` for controlling the behaviour diff --git a/cli/src/commands/file/mod.rs b/cli/src/commands/file/mod.rs index b642c3112..edd43abbe 100644 --- a/cli/src/commands/file/mod.rs +++ b/cli/src/commands/file/mod.rs @@ -15,6 +15,7 @@ pub mod chmod; pub mod list; pub mod show; +pub mod untrack; use crate::cli_util::CommandHelper; use crate::command_error::CommandError; @@ -26,6 +27,7 @@ pub enum FileCommand { Chmod(chmod::FileChmodArgs), List(list::FileListArgs), Show(show::FileShowArgs), + Untrack(untrack::FileUntrackArgs), } pub fn cmd_file( @@ -37,5 +39,6 @@ pub fn cmd_file( FileCommand::Chmod(args) => chmod::cmd_file_chmod(ui, command, args), FileCommand::List(args) => list::cmd_file_list(ui, command, args), FileCommand::Show(args) => show::cmd_file_show(ui, command, args), + FileCommand::Untrack(args) => untrack::cmd_file_untrack(ui, command, args), } } diff --git a/cli/src/commands/untrack.rs b/cli/src/commands/file/untrack.rs similarity index 97% rename from cli/src/commands/untrack.rs rename to cli/src/commands/file/untrack.rs index 4815d736c..25b84544b 100644 --- a/cli/src/commands/untrack.rs +++ b/cli/src/commands/file/untrack.rs @@ -28,7 +28,7 @@ use crate::ui::Ui; /// Stop tracking specified paths in the working copy #[derive(clap::Args, Clone, Debug)] -pub(crate) struct UntrackArgs { +pub(crate) struct FileUntrackArgs { /// Paths to untrack. They must already be ignored. /// /// The paths could be ignored via a .gitignore or .git/info/exclude (in @@ -38,10 +38,10 @@ pub(crate) struct UntrackArgs { } #[instrument(skip_all)] -pub(crate) fn cmd_untrack( +pub(crate) fn cmd_file_untrack( ui: &mut Ui, command: &CommandHelper, - args: &UntrackArgs, + args: &FileUntrackArgs, ) -> Result<(), CommandError> { let mut workspace_command = command.workspace_helper(ui)?; let store = workspace_command.repo().store().clone(); diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs index 66f0773b7..615003e07 100644 --- a/cli/src/commands/mod.rs +++ b/cli/src/commands/mod.rs @@ -52,7 +52,6 @@ mod squash; mod status; mod tag; mod unsquash; -mod untrack; mod util; mod version; mod workspace; @@ -155,7 +154,9 @@ enum Command { /// Undo an operation (shortcut for `jj op undo`) Undo(operation::undo::OperationUndoArgs), Unsquash(unsquash::UnsquashArgs), - Untrack(untrack::UntrackArgs), + // TODO: Delete `untrack` in jj 0.27+ + #[command(hide = true)] + Untrack(file::untrack::FileUntrackArgs), Version(version::VersionArgs), #[command(subcommand)] Workspace(workspace::WorkspaceCommand), @@ -230,7 +231,10 @@ pub fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), Co Command::Tag(args) => tag::cmd_tag(ui, command_helper, args), Command::Undo(args) => operation::undo::cmd_op_undo(ui, command_helper, args), Command::Unsquash(args) => unsquash::cmd_unsquash(ui, command_helper, args), - Command::Untrack(args) => untrack::cmd_untrack(ui, command_helper, args), + Command::Untrack(args) => { + let cmd = renamed_cmd("untrack", "file untrack", file::untrack::cmd_file_untrack); + cmd(ui, command_helper, args) + } Command::Util(args) => util::cmd_util(ui, command_helper, args), Command::Version(args) => version::cmd_version(ui, command_helper, args), Command::Workspace(args) => workspace::cmd_workspace(ui, command_helper, args), diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index 2304cb8c3..a9eba717f 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -39,6 +39,7 @@ This document contains the help content for the `jj` command-line program. * [`jj file chmod`↴](#jj-file-chmod) * [`jj file list`↴](#jj-file-list) * [`jj file show`↴](#jj-file-show) +* [`jj file untrack`↴](#jj-file-untrack) * [`jj fix`↴](#jj-fix) * [`jj git`↴](#jj-git) * [`jj git clone`↴](#jj-git-clone) @@ -91,7 +92,6 @@ This document contains the help content for the `jj` command-line program. * [`jj util config-schema`↴](#jj-util-config-schema) * [`jj undo`↴](#jj-undo) * [`jj unsquash`↴](#jj-unsquash) -* [`jj untrack`↴](#jj-untrack) * [`jj version`↴](#jj-version) * [`jj workspace`↴](#jj-workspace) * [`jj workspace add`↴](#jj-workspace-add) @@ -145,7 +145,6 @@ To get started, see the tutorial at https://github.com/martinvonz/jj/blob/main/d * `util` — Infrequently used commands such as for generating shell completions * `undo` — Undo an operation (shortcut for `jj op undo`) * `unsquash` — Move changes from a revision's parent into the revision -* `untrack` — Stop tracking specified paths in the working copy * `version` — Display version information * `workspace` — Commands for working with workspaces @@ -704,6 +703,7 @@ File operations * `chmod` — Sets or removes the executable bit for paths in the repo * `list` — List files in a revision * `show` — Print contents of files in a revision +* `untrack` — Stop tracking specified paths in the working copy @@ -773,6 +773,20 @@ If the given path is a directory, files in the directory will be visited recursi +## `jj file untrack` + +Stop tracking specified paths in the working copy + +**Usage:** `jj file untrack ...` + +###### **Arguments:** + +* `` — Paths to untrack. They must already be ignored. + + The paths could be ignored via a .gitignore or .git/info/exclude (in colocated repos). + + + ## `jj fix` Update files with formatting fixes or other changes @@ -2071,20 +2085,6 @@ If a working-copy commit gets abandoned, it will be given a new, empty commit. T -## `jj untrack` - -Stop tracking specified paths in the working copy - -**Usage:** `jj untrack ...` - -###### **Arguments:** - -* `` — Paths to untrack. They must already be ignored. - - The paths could be ignored via a .gitignore or .git/info/exclude (in colocated repos). - - - ## `jj version` Display version information diff --git a/cli/tests/runner.rs b/cli/tests/runner.rs index 116667ada..b1fcc5b3a 100644 --- a/cli/tests/runner.rs +++ b/cli/tests/runner.rs @@ -29,6 +29,7 @@ mod test_duplicate_command; mod test_edit_command; mod test_file_chmod_command; mod test_file_print_command; +mod test_file_untrack_command; mod test_fix_command; mod test_generate_md_cli_help; mod test_git_clone; @@ -68,7 +69,6 @@ mod test_tag_command; mod test_templater; mod test_undo; mod test_unsquash_command; -mod test_untrack_command; mod test_util_command; mod test_working_copy; mod test_workspaces; diff --git a/cli/tests/test_untrack_command.rs b/cli/tests/test_file_untrack_command.rs similarity index 85% rename from cli/tests/test_untrack_command.rs rename to cli/tests/test_file_untrack_command.rs index 53f08edc2..3d7217961 100644 --- a/cli/tests/test_untrack_command.rs +++ b/cli/tests/test_file_untrack_command.rs @@ -38,23 +38,24 @@ fn test_untrack() { 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", "@-"]); + let stderr = + test_env.jj_cmd_failure(&repo_path, &["file", "untrack", "file1", "--at-op", "@-"]); insta::assert_snapshot!(stderr, @r###" Error: This command must be able to update the working copy. Hint: Don't use --at-op. "###); // Errors out when no path is specified - let stderr = test_env.jj_cmd_cli_error(&repo_path, &["untrack"]); + let stderr = test_env.jj_cmd_cli_error(&repo_path, &["file", "untrack"]); insta::assert_snapshot!(stderr, @r###" error: the following required arguments were not provided: ... - Usage: jj untrack ... + Usage: jj file untrack ... For more information, try '--help'. "###); // Errors out when a specified file is not ignored - let stderr = test_env.jj_cmd_failure(&repo_path, &["untrack", "file1", "file1.bak"]); + let stderr = test_env.jj_cmd_failure(&repo_path, &["file", "untrack", "file1", "file1.bak"]); insta::assert_snapshot!(stderr, @r###" Error: 'file1' is not ignored. Hint: Files that are not ignored will be added back by the next command. @@ -68,7 +69,10 @@ fn test_untrack() { assert!(files_before.contains("file1.bak\n")); let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["untrack", "file1.bak"]); insta::assert_snapshot!(stdout, @""); - insta::assert_snapshot!(stderr, @""); + insta::assert_snapshot!(stderr, @r###" + Warning: `jj untrack` is deprecated; use `jj file untrack` instead, which is equivalent + Warning: `jj untrack` will be removed in a future version, and this will be a hard error + "###); let files_after = test_env.jj_cmd_success(&repo_path, &["file", "list"]); // The file is no longer tracked assert!(!files_after.contains("file1.bak")); @@ -79,7 +83,7 @@ fn test_untrack() { assert!(repo_path.join("file2.bak").exists()); // Errors out when multiple specified files are not ignored - let stderr = test_env.jj_cmd_failure(&repo_path, &["untrack", "target"]); + let stderr = test_env.jj_cmd_failure(&repo_path, &["file", "untrack", "target"]); assert_eq!( stderr, format!( @@ -91,7 +95,7 @@ fn test_untrack() { // Can untrack after adding to ignore patterns std::fs::write(repo_path.join(".gitignore"), ".bak\ntarget/\n").unwrap(); - let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["untrack", "target"]); + let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["file", "untrack", "target"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @""); let files_after = test_env.jj_cmd_success(&repo_path, &["file", "list"]); @@ -117,7 +121,7 @@ fn test_untrack_sparse() { file2 "###); test_env.jj_cmd_ok(&repo_path, &["sparse", "set", "--clear", "--add", "file1"]); - let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["untrack", "file2"]); + let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["file", "untrack", "file2"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @""); let stdout = test_env.jj_cmd_success(&repo_path, &["file", "list"]); diff --git a/docs/tutorial.md b/docs/tutorial.md index 9d6342737..6e4faed68 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -70,7 +70,7 @@ Parent commit: orrkosyo 7fd1a60b master | (empty) Merge pull request #6 from Spa Note that you didn't have to tell Jujutsu to add the change like you would with `git add`. You actually don't even need to tell it when you add new files or remove existing files. To untrack a path, add it to your `.gitignore` and run -`jj untrack `. +`jj file untrack `. To see the diff, run `jj diff`: diff --git a/docs/working-copy.md b/docs/working-copy.md index 4be1e8a8c..1fbf2ad5e 100644 --- a/docs/working-copy.md +++ b/docs/working-copy.md @@ -17,7 +17,7 @@ if you add a new file to the working copy, it will be automatically committed once you run e.g. `jj st`. Similarly, if you remove a file from the working copy, it will implicitly be untracked. To untrack a file while keeping it in the working copy, first make sure it's [ignored](#ignored-files) and then run -`jj untrack `. +`jj file untrack `. ## Conflicts