Skip to content

Commit

Permalink
cli: move "untrack" to "file" subcommand
Browse files Browse the repository at this point in the history
I don't think "jj untrack" is frequently used, and I think it is a "file"
command rather than "workspace".
  • Loading branch information
yuja committed Aug 25, 2024
1 parent 3c15f81 commit 6b65f8a
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 33 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions cli/src/commands/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,7 @@ pub enum FileCommand {
Chmod(chmod::FileChmodArgs),
List(list::FileListArgs),
Show(show::FileShowArgs),
Untrack(untrack::FileUntrackArgs),
}

pub fn cmd_file(
Expand All @@ -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),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
10 changes: 7 additions & 3 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ mod squash;
mod status;
mod tag;
mod unsquash;
mod untrack;
mod util;
mod version;
mod workspace;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
32 changes: 16 additions & 16 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 <PATHS>...`
###### **Arguments:**
* `<PATHS>` — 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
Expand Down Expand Up @@ -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 <PATHS>...`
###### **Arguments:**
* `<PATHS>` — 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
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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:
<PATHS>...
Usage: jj untrack <PATHS>...
Usage: jj file untrack <PATHS>...
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.
Expand All @@ -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"));
Expand All @@ -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!(
Expand All @@ -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"]);
Expand All @@ -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"]);
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path>`.
`jj file untrack <path>`.

To see the diff, run `jj diff`:

Expand Down
2 changes: 1 addition & 1 deletion docs/working-copy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path>`.
`jj file untrack <path>`.


## Conflicts
Expand Down

0 comments on commit 6b65f8a

Please sign in to comment.