Skip to content

Commit

Permalink
feat: Create a file command containing print and chmod
Browse files Browse the repository at this point in the history
- rearrange the files involved to be more clear about structure
- deprecate existing `jj cat` and `jj chmod`
  • Loading branch information
fowles committed Jun 17, 2024
1 parent 2de73f5 commit 47bd6f4
Show file tree
Hide file tree
Showing 18 changed files with 310 additions and 214 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `jj split --siblings` is deprecated in favor of `jj split --parallel` (to
match `jj parallelize`).

* `jj file print` (aka `jj file cat`) replaces `jj cat`.

* `jj file chmod` replaces `jj chmod`.

### New features

* Support background filesystem monitoring via watchman triggers enabled with
Expand All @@ -44,6 +48,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Conflicted files are individually simplified before being materialized.

* `jj file` now groups commands for working with files.

### Fixed bugs

## [0.18.0] - 2024-06-05
Expand Down
17 changes: 17 additions & 0 deletions cli/src/commands/chmod.rs → cli/src/commands/file/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ pub(crate) struct ChmodArgs {
paths: Vec<String>,
}

#[instrument(skip_all)]
pub(crate) fn deprecated_cmd_chmod(
ui: &mut Ui,
command: &CommandHelper,
args: &ChmodArgs,
) -> Result<(), CommandError> {
writeln!(
ui.warning_default(),
"`jj chmod` is deprecated; use `jj file chmod` instead, which is equivalent"
)?;
writeln!(
ui.warning_default(),
"`jj chmod` will be removed in a future version, and this will be a hard error"
)?;
cmd_chmod(ui, command, args)
}

#[instrument(skip_all)]
pub(crate) fn cmd_chmod(
ui: &mut Ui,
Expand Down
38 changes: 38 additions & 0 deletions cli/src/commands/file/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2020-2023 The Jujutsu Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod chmod;
pub mod print;

use crate::cli_util::CommandHelper;
use crate::command_error::CommandError;
use crate::ui::Ui;

/// File operations.
#[derive(clap::Subcommand, Clone, Debug)]
pub enum FileCommand {
Print(print::PrintArgs),
Chmod(chmod::ChmodArgs),
}

pub fn cmd_file(
ui: &mut Ui,
command: &CommandHelper,
subcommand: &FileCommand,
) -> Result<(), CommandError> {
match subcommand {
FileCommand::Print(sub_args) => print::cmd_print(ui, command, sub_args),
FileCommand::Chmod(sub_args) => chmod::cmd_chmod(ui, command, sub_args),
}
}
23 changes: 20 additions & 3 deletions cli/src/commands/cat.rs → cli/src/commands/file/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::ui::Ui;
/// If the given path is a directory, files in the directory will be visited
/// recursively.
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct CatArgs {
pub(crate) struct PrintArgs {
/// The revision to get the file contents from
#[arg(long, short, default_value = "@")]
revision: RevisionArg,
Expand All @@ -44,10 +44,27 @@ pub(crate) struct CatArgs {
}

#[instrument(skip_all)]
pub(crate) fn cmd_cat(
pub(crate) fn deprecated_cmd_cat(
ui: &mut Ui,
command: &CommandHelper,
args: &CatArgs,
args: &PrintArgs,
) -> Result<(), CommandError> {
writeln!(
ui.warning_default(),
"`jj cat` is deprecated; use `jj file print` instead, which is equivalent"
)?;
writeln!(
ui.warning_default(),
"`jj cat` will be removed in a future version, and this will be a hard error"
)?;
cmd_print(ui, command, args)
}

#[instrument(skip_all)]
pub(crate) fn cmd_print(
ui: &mut Ui,
command: &CommandHelper,
args: &PrintArgs,
) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?;
let commit = workspace_command.resolve_single_rev(&args.revision)?;
Expand Down
17 changes: 10 additions & 7 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ mod backout;
#[cfg(feature = "bench")]
mod bench;
mod branch;
mod cat;
mod checkout;
mod chmod;
mod commit;
mod config;
mod debug;
Expand All @@ -28,6 +26,7 @@ mod diff;
mod diffedit;
mod duplicate;
mod edit;
mod file;
mod files;
mod fix;
mod git;
Expand Down Expand Up @@ -77,11 +76,12 @@ enum Command {
Bench(bench::BenchCommand),
#[command(subcommand)]
Branch(branch::BranchCommand),
#[command(alias = "print")]
Cat(cat::CatArgs),
#[command(alias = "print", hide = true)]
Cat(file::print::PrintArgs),
#[command(hide = true)]
Checkout(checkout::CheckoutArgs),
Chmod(chmod::ChmodArgs),
#[command(hide = true)]
Chmod(file::chmod::ChmodArgs),
Commit(commit::CommitArgs),
#[command(subcommand)]
Config(config::ConfigCommand),
Expand All @@ -92,6 +92,8 @@ enum Command {
Diffedit(diffedit::DiffeditArgs),
Duplicate(duplicate::DuplicateArgs),
Edit(edit::EditArgs),
#[command(subcommand)]
File(file::FileCommand),
Files(files::FilesArgs),
Fix(fix::FixArgs),
#[command(subcommand)]
Expand Down Expand Up @@ -171,8 +173,9 @@ pub fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), Co
Command::Config(sub_args) => config::cmd_config(ui, command_helper, sub_args),
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) => cat::cmd_cat(ui, command_helper, sub_args),
Command::Cat(sub_args) => file::print::deprecated_cmd_cat(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 Expand Up @@ -210,7 +213,7 @@ pub fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), Co
Command::Workspace(sub_args) => workspace::cmd_workspace(ui, command_helper, sub_args),
Command::Sparse(sub_args) => sparse::cmd_sparse(ui, command_helper, sub_args),
Command::Tag(sub_args) => tag::cmd_tag(ui, command_helper, sub_args),
Command::Chmod(sub_args) => chmod::cmd_chmod(ui, command_helper, sub_args),
Command::Chmod(sub_args) => file::chmod::deprecated_cmd_chmod(ui, command_helper, sub_args),
Command::Git(sub_args) => git::cmd_git(ui, command_helper, sub_args),
Command::Util(sub_args) => util::cmd_util(ui, command_helper, sub_args),
#[cfg(feature = "bench")]
Expand Down
117 changes: 65 additions & 52 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ This document contains the help content for the `jj` command-line program.
* [`jj branch set`↴](#jj-branch-set)
* [`jj branch track`↴](#jj-branch-track)
* [`jj branch untrack`↴](#jj-branch-untrack)
* [`jj cat`↴](#jj-cat)
* [`jj chmod`↴](#jj-chmod)
* [`jj commit`↴](#jj-commit)
* [`jj config`↴](#jj-config)
* [`jj config list`↴](#jj-config-list)
Expand All @@ -36,6 +34,9 @@ This document contains the help content for the `jj` command-line program.
* [`jj diffedit`↴](#jj-diffedit)
* [`jj duplicate`↴](#jj-duplicate)
* [`jj edit`↴](#jj-edit)
* [`jj file`↴](#jj-file)
* [`jj file print`↴](#jj-file-print)
* [`jj file chmod`↴](#jj-file-chmod)
* [`jj files`↴](#jj-files)
* [`jj fix`↴](#jj-fix)
* [`jj git`↴](#jj-git)
Expand Down Expand Up @@ -108,15 +109,14 @@ To get started, see the tutorial at https://github.com/martinvonz/jj/blob/main/d
* `abandon`Abandon a revision
* `backout`Apply the reverse of a revision on top of another revision
* `branch`Manage branches
* `cat`Print contents of files in a revision
* `chmod`Sets or removes the executable bit for paths in the repo
* `commit`Update the description and create a new change on top
* `config`Manage config options
* `describe`Update the change description or other metadata
* `diff`Compare file contents between two revisions
* `diffedit`Touch up the content changes in a revision with a diff editor
* `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
Expand Down Expand Up @@ -390,54 +390,6 @@ A non-tracking remote branch is just a pointer to the last-fetched remote branch
## `jj cat`
Print contents of files in a revision
If the given path is a directory, files in the directory will be visited recursively.
**Usage:** `jj cat [OPTIONS] <PATHS>...`
###### **Arguments:**
* `<PATHS>` — Paths to print
###### **Options:**
* `-r`, `--revision <REVISION>` — The revision to get the file contents from
Default value: `@`
## `jj chmod`
Sets or removes the executable bit for paths in the repo
Unlike the POSIX `chmod`, `jj chmod` also works on Windows, on conflicted files, and on arbitrary revisions.
**Usage:** `jj chmod [OPTIONS] <MODE> <PATHS>...`
###### **Arguments:**
* `<MODE>`
Possible values:
- `n`:
Make a path non-executable (alias: normal)
- `x`:
Make a path executable (alias: executable)
* `<PATHS>` — Paths to change the executable bit for
###### **Options:**
* `-r`, `--revision <REVISION>` — The revision to update
Default value: `@`
## `jj commit`
Update the description and create a new change on top
Expand Down Expand Up @@ -693,6 +645,67 @@ For more information, see https://martinvonz.github.io/jj/latest/FAQ#how-do-i-re
## `jj file`
File operations
**Usage:** `jj file <COMMAND>`
###### **Subcommands:**
* `print` — Print contents of files in a revision
* `chmod` — Sets or removes the executable bit for paths in the repo
## `jj file print`
Print contents of files in a revision
If the given path is a directory, files in the directory will be visited recursively.
**Usage:** `jj file print [OPTIONS] <PATHS>...`
###### **Arguments:**
* `<PATHS>` — Paths to print
###### **Options:**
* `-r`, `--revision <REVISION>` — The revision to get the file contents from
Default value: `@`
## `jj file chmod`
Sets or removes the executable bit for paths in the repo
Unlike the POSIX `chmod`, `jj chmod` also works on Windows, on conflicted files, and on arbitrary revisions.
**Usage:** `jj file chmod [OPTIONS] <MODE> <PATHS>...`
###### **Arguments:**
* `<MODE>`
Possible values:
- `n`:
Make a path non-executable (alias: normal)
- `x`:
Make a path executable (alias: executable)
* `<PATHS>` — Paths to change the executable bit for
###### **Options:**
* `-r`, `--revision <REVISION>` — The revision to update
Default value: `@`
## `jj files`
List files in a revision
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ mod test_advance_branches;
mod test_alias;
mod test_branch_command;
mod test_builtin_aliases;
mod test_cat_command;
mod test_checkout;
mod test_chmod_command;
mod test_commit_command;
mod test_commit_template;
mod test_concurrent_operations;
Expand All @@ -27,6 +25,8 @@ mod test_diff_command;
mod test_diffedit_command;
mod test_duplicate_command;
mod test_edit_command;
mod test_file_chmod_command;
mod test_file_print_command;
mod test_fix_command;
mod test_generate_md_cli_help;
mod test_git_clone;
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_acls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn test_cat() {

SecretBackend::adopt_git_repo(&repo_path);

let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["cat", "."]);
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["file", "print", "."]);
insta::assert_snapshot!(stdout.replace('\\', "/"), @r###"
foo
baz
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_diffedit_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ fn test_diffedit_merge() {
A file3
"###);
assert!(!repo_path.join("file1").exists());
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file2"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["file", "print", "file2"]);
insta::assert_snapshot!(stdout, @r###"
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
Expand Down
Loading

0 comments on commit 47bd6f4

Please sign in to comment.